How can I add a new Item to fabric? - java

I'm trying to code a mod, which adds a new Item to the game and I'm following a tutorial on youtube. I also looked everything up on the fabric website, but the code doesn't work.
Here is the code I used. It is from the fabric wiki:
public static final Item CUSTOM_ITEM = new Item(new FabricItemSettings().group(ItemGroup.MISC));
#Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("tutorial", "custom_item"), CUSTOM_ITEM);
}
Somehow in my library the .group() function doesn't exist and that's the same with other functions.
Do I have to download something or how can I fix this?
I tried adding a new Item to my mod, but it didn't work.

Related

Bukkit - ShapedRecipe is deprecated

I want to make custom item with custom recipe. I created class with 2 methods, item and customRecipe.
My class looks like this
public class LifeCrystal implements Listener {
private ItemStack item = new ItemStack(Material.DIAMOND);
private ItemMeta meta = item.getItemMeta();
private Plugin plugin = BelieveMe.getPlugin(BelieveMe.class);
public void Item(Player player){
meta.setDisplayName(ChatColor.GOLD + "Life Crystal");
ArrayList<String> lores = new ArrayList<>();
lores.add("Increase your life points");
lores.add("...or revive someone");
meta.setLore(lores);
item.setItemMeta(meta);
}
public void customRecipe(){
ShapedRecipe r = new ShapedRecipe(item);
r.shape(" E ", "LAL", "DGD");
r.setIngredient('E', Material.EMERALD);
r.setIngredient('L', Material.LAPIS_LAZULI);
r.setIngredient('A', Material.GOLDEN_APPLE);
r.setIngredient('D', Material.DIAMOND);
r.setIngredient('G', Material.GOLD_INGOT);
plugin.getServer().addRecipe(r);
}
}
"new ShapedRecipe(item)" is crossed and my error message is "ShapedRecipe is deprecated". I searched for that and find some information about NamespacedKey. I really don't know what to do now
It appears as if you just need to change your ShapedRecipe object constructor (according to the JavaDocs). Changing it to something like:
NamespacedKey nsKey = new NamespacedKey(plugin, "unique_key_here");
ShapedRecipe r = new ShapedRecipe(nsKey, item);
should work on the latest version (1.14.4-R0.1-snapshot at time of writing). There is also a guide written on the official Spigot wiki, linked here.
Quick note: From researching, seems the key HAS to be unique per 1.11 requirements, so make sure you have something that doesn't conflict with any vanilla recipes.

Trying to add google maps to a Vaadin view

I'm trying to use the Vaadin GoogleMaps plugin on our web application to show a small window with Google maps. I have this:
private GoogleMap googleMap;
private LatLon mapMarkerlatLon;
private GoogleMapMarker googleMapMarker;
private final String apiKey = "https://maps.googleapis.com/maps/api/js?key=<ourKey>=initMap";
#Override
public void enter(ViewChangeEvent event) {
//googleMap = new GoogleMap(apiKey, null, null);
//As suggested:
googleMap = new GoogleMap(apiKey, null, "english");
mapMarkerlatLon = new LatLon(0,0);
googleMap.setCenter(mapMarkerlatLon);
googleMapMarker = new GoogleMapMarker("Tal", mapMarkerlatLon, false);
googleMap.addMarker(googleMapMarker);
initializeViewContent();
}
A bit further down my class..
protected CssLayout initializeViewContent() {
CssLayout sideBarLayout = new CssLayout();
sideBarLayout.addStyleName("sidebar");
/* ... */
sideBarLayout.addComponent(googleMap);
return sideBarLayout;
}
There's more stuff around the class,but basically this is the "important" bit. When I load the page, I got this:
More or less, translated to english, it says "An error occured. This webpage did not load Google Maps correctly. Discover the technical details on the Javascript console."
EDITED: Firfeox Console is as empyt as my knowledge of this topic.
Chrome's console is telling me about a missing keyMapError.
I've tried changin the key format to:
{ourKey}
{ourKey}=initMap
key={ourKey}=initMap
And, well, I'm getting tired of playing with combinatory. The key works, as it was given to me with a small demo that works flawlessly.
What I'm doing wrong?

Method called in constructor is not working after built in java netbeans

Here while I run java project in netbeans all things are working okay. But after they are built there is not any item added in combobox as it works during netbeans run. The sample code is given below.
First Login JFrame
public class Login_Frame extends javax.swing.JFrame {
welcome w = new welcome();
public Login_Frame() {
initComponents();
}
//button action perform event for dispose this window and open new welcome window
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
.
.
w.setVisible(true);
this.dispose();
.
.
}
}
Second JFrame
public final class welcome extends javax.swing.JFrame {
// comboitem is class in which method for adding item in combobox from sqlite
db is declared
comboitem c = new comboitem();
// textclass is class in which method for changing lowercase text entered in
text to uppercase is declared
textclass tc = new textclass();
public welcome() {
// while I try to run the project using netbeans run project option
// logincall() method initialized and work fine.
Problem
After project built when I try to run the jar file from the cmd. it runs without any
error but logincall() method doesn't work or may be not initialized.
initComponents();
logincall();
.
.
}
public void logincall(){
//Remarks
//tc.uppercase() method is working fine after built. But other c.but_stn() like
// doen't.while during running project through netbeans all thing working fine.
c.bus_stn();
c.bus_trl();
c.inq_stn();
c.editframe();
c.userlist();
c.editTrainStation();
c.editFlightStation();
c.flightFlight();
c.pickupstand();
tc.uppercase();
}
I didn't know what is wrong with it. I searched on google but didn't find any proper answer.
There also any error showing up in netbeans. Please fill free to ask any questions if more information is needed. I appreciate all your replies.
This is my Welcome Main class's main method.
public static void main(String args[]) {
...
look and feel auto generated code
....
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new welcome().setVisible(true);
}
});
}
A couple of things that might be an issue here:
1) Are you running your GUI on the EventDispatchThread? this is mandatory for java swing GUI to be able to work properly. The main reason for this is concurrency. Details here.
2) Are you re-rendering your combobox? it is important that you do this because changes to GUI elements may not be immediately shown.
3) What Database are you using? in order to determine if the fault lies in the code or the DB you could write a test using static data, if it loads in the IDE and outside of it chances are that your code is correct but the DB isn't

Is there a way for push notifications in libGDX (Android and iOS projects)?

Does someone knows if it is possible to add push notifications(like Amazon Simple Notification Service) in an Android and iOS with RoboVM libGDX projects? And if it is possible, are there any good tutorials or good hints how to implement such things?
I would be happy about every hint how I can implement it.
Hi I know this is an old question but I was struggling to find a solution for this specially for iOS, but I finally found a way. If the explanation below is confusing and you prefer to see an example here is a github repo with a sample project:
Repo GitHub
I only show the code for iOS see the repo for Android.
The idea is simple you need to create a class that handles sending a notification for each platform on each of your projects (Android and iOS) and have it implement an interface called NotificationsHandler.
NotificationsHandler:
public interface NotificationsHandler {
public void showNotification(String title, String text);
}
iOS Adapter:
public class AdapteriOS implements NotificationsHandler {
public AdapteriOS () {
//Registers notifications, it will ask user if ok to receive notifications from this app, if user selects no then no notifications will be received
UIApplication.getSharedApplication().registerUserNotificationSettings(UIUserNotificationSettings.create(UIUserNotificationType.Alert, null));
UIApplication.getSharedApplication().registerUserNotificationSettings(UIUserNotificationSettings.create(UIUserNotificationType.Sound, null));
UIApplication.getSharedApplication().registerUserNotificationSettings(UIUserNotificationSettings.create(UIUserNotificationType.Badge, null));
//Removes notifications indicator in app icon, you can do this in a different way
UIApplication.getSharedApplication().setApplicationIconBadgeNumber(0);
UIApplication.getSharedApplication().cancelAllLocalNotifications();
}
#Override
public void showNotification(final String title, final String text) {
NSOperationQueue.getMainQueue().addOperation(new Runnable() {
#Override
public void run() {
NSDate date = new NSDate();
//5 seconds from now
NSDate secondsMore = date.newDateByAddingTimeInterval(5);
UILocalNotification localNotification = new UILocalNotification();
localNotification.setFireDate(secondsMore);
localNotification.setAlertBody(title);
localNotification.setAlertAction(text);
localNotification.setTimeZone(NSTimeZone.getDefaultTimeZone());
localNotification.setApplicationIconBadgeNumber(UIApplication.getSharedApplication().getApplicationIconBadgeNumber() + 1);
UIApplication.getSharedApplication().scheduleLocalNotification(localNotification);
}
});
}
}
Now by default Libgdx passes your ApplicationListener or Game object to AndroidLauncher and IOSLauncher along with a configuration object. The trick is to pass the class we created earlier to the ApplicationListener so that you can use it inside your Core project. Simple enough:
public class IOSLauncher extends IOSApplication.Delegate {
#Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
// This is your ApplicationListener or Game class
// it will be called differently depending on what you
// set up when you created the libgdx project
MainGame game = new MainGame();
// We instantiate the iOS Adapter
AdapteriOS adapter = new AdapteriOS();
// We set the handler, you must create this method in your class
game.setNotificationHandler(adapter);
return new IOSApplication(game, config);
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
}
Now that you have a reference to the implementation of NotificationHandler you can simply call it through your Core project.
public class MainGame extends Game {
// This is the notificatino handler
public NotificationHandler notificationHandler;
#Override
public void create () {
// Do whatever you do when your game is created
// ...
}
#Override
public void render () {
super.render();
// This is just an example but you
// can now send notifications in your project
if(condition)
notificationHandler.showNotification("Title", "Content");
}
#Override
public void dispose() {
super.dispose();
}
// This is the method we created to set the notifications handler
public void setNotificationHandler(NotificationHandler handler) {
this.notificationHandler = handler;
}
}
One last thing
If you need to run the Desktop version then you will need to do the same thing for Desktop otherwise you might get errors, it will not do anything on the Desktop, or you can check the platform before calling the method showNotfication. You can clone the repo where I do this:
Repo GitHub
I've never done it myself. But you can use this tutorial to find out how to write Android specific code in your libGDX project. Your Android code could then receive the notifications and trigger a callback in libGDX. I hope this is at least a step in the right direction.
However I' not sure about doing the same for iOS.

EclipseRCP - Update menu items programmcatically

Ik have used this tutorial to define a menu that is built up during runtime. But the next step I want to take is when some event occurs I want to re-build this menu programmatically, for instance by saying to the menu manager, refresh or something like that? Any idea how I can do this?
You can tell the menu manager to remove all items each time the menu is shown, giving you the opportunity to rebuild your menu:
MenuManager mm = new MenuManager();
mm.setRemoveAllWhenShown(true);
mm.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if(giraffes) {
Action giraffeAction = new Action("Giraffe") {
public void run() {
// do giraffe-y stuff
}
};
mgr.add(giraffeAction);
}
}
});
Control myControl = myViewer.getControl();
myControl().setMenu(mm.createContextMenu(myControl));
Instead of using an ExtensionContributionFactory, use org.eclipse.ui.menus to add a dynamic element to the menu you want. The implementation class you provide subclasses org.eclipse.ui.actions.CompoundContributionItem and you will have the opportunity to rebuild that part of the menu on every menu open.
EDIT: add pointer to example.
See http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.ui.examples.contributions/plugin.xml#n666 for the plugin.xml difference. The implementing class is also contained in that plugin.

Categories