-
Posts
42 -
Joined
-
Last visited
-
Days Won
1
Posts posted by SaltStation
-
-
Yes it is this class:
public static BlockItem ItemfromBlock(Block p) { return (BlockItem) new BlockItem(p, (new Item.Properties()).group(ItemGroup.BUILDING_BLOCKS)).setRegistryName(p.getRegistryName()); } }
-
Because all three blocks are the same except in name I made the following class:
Spoilerpublic class BasicOre { public static Block ore(String name){ return new Block(Block.Properties.create(Material.ROCK) .lightValue(0) .hardnessAndResistance(3,15) .harvestLevel(1) .harvestTool(net.minecraftforge.common.ToolType.PICKAXE)).setRegistryName(name); } }
-
I wanted to try the DeferredRegister to register items and blocks, but I always get this error:
QuoteException caught during firing event: Attempted to set registry name with existing registry name! New: opus:sulfureore Old: opus:sulfureore
RegistryHandler code :
Spoiler//Register private static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID); private static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID); //Register Blocks public static final RegistryObject<Block> SULFUREORE_BLOCK = BLOCKS.register("sulfureore",() -> new BasicOre().ore("sulfureore")); public static final RegistryObject<Block> CINNABARORE_BLOCK = BLOCKS.register("cinnabarore",() -> new BasicOre().ore("cinnabarore")); public static final RegistryObject<Block> SALTORE_BLOCK = BLOCKS.register("saltore",() -> new BasicOre().ore("saltore")); //Register Items public static final RegistryObject<Item> SULFUREORE_ITEM = ITEMS.register("sulfureore",() -> new ItemHelper().ItemfromBlock(new BasicOre().ore("sulfureore"))); public static final RegistryObject<Item> CINNABARORE_ITEM = ITEMS.register("cinnabarore",() -> new ItemHelper().ItemfromBlock(new BasicOre().ore("cinnabarore"))); public static final RegistryObject<Item> SALTORE_ITEM = ITEMS.register("saltore",() -> new ItemHelper().ItemfromBlock(new BasicOre().ore("saltore"))); public static void registerall(){ BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); }
Main mod class:
Spoilerpublic Opus() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); RegistryHandler.registerall(); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); }
There are blocks with the same name as items, but this should be fine shouldn't it?
How does this error happen and how would I fix it?
Thanks in advance!
-
I want to generate ore only next to underground lava lakes, but I don't know how.
I have come up with two approaches so far.
- When a lava lake is generated the ore is placed on nearby stone.
- The game generates the ore like normal, but checks if lava is nearby before placing the ore.
Which approach is the better or is there a different way to do this?
-
Just override the getDrops method and add the item to the drops Itemstack.
-
Thanks it works.
-
Can you be more specific?
-
For a custom capability you need to have an Interface, Default implementation, Storage, Provider and a Factory.
If you want to attach the capability to a player you will need to use an attachcapability event and register it in your main mod class.
If your Player is teleported or respawns you will also have to manage your capability so you dont lose data.
Here is an example:
Ignore wrong grammar...
-
Hello everyone,
I want to get an EntityPlayerMP object by using a UUID but my current method only works if the player in question is online.
Is there a way to get a list of all Players who where on the server at some point?
Current Method:
SpoilerMinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); player = server.getPlayerList().getPlayerByUUID(id);
I want to get the statistcmanagerserver from the player by the way.
-
Youtube tutorials are usually not reliable as many creators take shortcuts which are not very appreciated on this Forum.
An amazing source for information in addition to the ones named by GloriousAlpaca are Minecraft classes and methods themselves and other mods which have an open Github.
I think key bindings are saved in the options.txt which you could edit.
I would not recommend changing the default Ui as changing minecraft code may make other mods incompatible.
Opening a second inventory or a second hotbar is possible by drawing a ui for the hotbar and having a custom container and gui for the inventory.
If you want to save data to the player you need to make your own capability which you attach to the player.
- 2
-
I think you need to have a TileEntity and use IFluidHandler.
If the amount of fluid changes you can instruct the TileEntity to change the blockstate of the cauldron.
-
Hello everyone.
After the player uses a Gui a value in the NBT of the held item is supposed to change, but the hand always returns null.
EnumHand hand = mc.player.getActiveHand(); mc.player.getHeldItem(hand).getTagCompound().setString("spell","test");
-
Working as intended!
-
I just hold rightclick in this video.
The upload here failed so here is a link to google drive:
https://drive.google.com/open?id=1Xfw6LoKfH6m_OqXlkFFqhSyXxR-KoHpT
Code:
Spoilerpublic class Catalyst extends ItemBase{ public Catalyst(String name) { super(name); } @Override public int getMaxItemUseDuration(ItemStack stack) { return 7000; } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; } }
-
I copied the methods from the ItemBow class, but the animation is kind of not working.
You can see the item twitching in first person, but no animation from any other perspective.
Am I missing something?
Spoiler@Override public int getMaxItemUseDuration(ItemStack stack) { return 7000; } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; }
-
How do I make an Item use an animation from a minecraft item like a bow for example?
-
No you only have one item but depending on the parameters it can have different damage/effects/whateveryouwant
Sword(String name, int material, String infusion)
in your ModItem class:
FIRESWORD_LEVEL_TWO = new Sword(firesword_level_two,2, fire)
-
You could add additional parameters to the constructor of your sword class.
-
Hello everyone.
The problem I have is that every time I try accessing my capability I get a null pointer exception.
Do I have to send packets to the client at the start of the game to prevent this?
Because I thought you only need packets to update information.
Default Implementation:
Spoilerpublic class Fatigue implements IFatigue { private double fatigue = 0; private double limit = 20; private double regen = 0; @Override public void setFatigue(double points) { this.fatigue=points; } public void setLimit(double points) { this.limit=points; } public void setRegen(double points) { this.regen=points; } @Override public void add(double points) { this.fatigue+=points; } @Override public void remove(double points) { this.fatigue-=points; } @Override public double getFatigue() { return this.fatigue ; } @Override public double getLimit() { return this.limit ; } @Override public double getRegen() { return this.regen ; } }
Storage:
Spoilerpublic class FatigueStorage implements Capability.IStorage<IFatigue> { @Override public NBTBase writeNBT(Capability<IFatigue> capability, IFatigue instance, EnumFacing side) { NBTTagCompound tag = new NBTTagCompound(); tag.setDouble("fatigue", instance.getFatigue()); tag.setDouble("fatigue_limit", instance.getLimit()); tag.setDouble("cosmo_regen", instance.getRegen()); System.out.println("written to NBT(Fatigue): "+instance.getFatigue()); return tag; } @Override public void readNBT(Capability<IFatigue> capability, IFatigue instance, EnumFacing side, NBTBase nbt) { NBTTagCompound tag = (NBTTagCompound) nbt; instance.setFatigue(tag.getDouble("fatigue")); instance.setLimit(tag.getDouble("fatigue_limit")); instance.setRegen(tag.getDouble("fatigue_regen")); System.out.println("read from NBT(Fatigue): "+instance.getFatigue()); } }
Provider:
Spoilerpublic class FatigueProvider implements ICapabilitySerializable<NBTBase> { @CapabilityInject(IFatigue.class) public static final Capability<IFatigue> FATIGUE_CAPABILITY = null; private IFatigue instance = FATIGUE_CAPABILITY.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing){ return capability == FATIGUE_CAPABILITY; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == FATIGUE_CAPABILITY ? FATIGUE_CAPABILITY.<T> cast(this.instance) : null; } @Override public NBTBase serializeNBT(){ return FATIGUE_CAPABILITY.getStorage().writeNBT(FATIGUE_CAPABILITY, this.instance, null); } @Override public void deserializeNBT(NBTBase nbt) { FATIGUE_CAPABILITY.getStorage().readNBT(FATIGUE_CAPABILITY, this.instance,null,nbt); } }
Capability Handler:
Spoilerpublic class CapabilityHandeler { public static final ResourceLocation FATIGUE_CAPABILITY = new ResourceLocation(Reference.MOD_ID,"fatigue"); @SubscribeEvent public void attachCapability(AttachCapabilitiesEvent<Entity> event){ if (!(event.getObject() instanceof EntityPlayer)) return; event.addCapability(FATIGUE_CAPABILITY, new FatigueProvider()); } }
Other Handler:
Spoilerpublic class FatiguePlayerHandeler { @SubscribeEvent public void onPlayerSleep(PlayerSleepInBedEvent event) { EntityPlayer player = event.getEntityPlayer(); IFatigue fatigue = player.getCapability(FatigueProvider.FATIGUE_CAPABILITY, null); System.out.println(fatigue.getLimit()); System.out.println(fatigue.getFatigue()); System.out.println(fatigue.getFatigue()); } @SubscribeEvent public void onPlayerClone(PlayerEvent.Clone event){ EntityPlayer player = event.getEntityPlayer(); IFatigue fatigue = player.getCapability(FatigueProvider.FATIGUE_CAPABILITY, null); IFatigue oldFatigue = event.getOriginal().getCapability(FatigueProvider.FATIGUE_CAPABILITY, null); fatigue.setFatigue(oldFatigue.getFatigue()); fatigue.setLimit(oldFatigue.getLimit()); fatigue.setRegen(oldFatigue.getRegen()); } }
Common Proxy:
Spoilerpublic class CommonProxy { public void preInit() { CapabilityManager.INSTANCE.register(IFatigue.class,new FatigueStorage(),Fatigue.class); MinecraftForge.EVENT_BUS.register(new CapabilityHandeler()); } public void init() {} public void postInit() {} public void registerItemRenderer(Item item, int meta, String id) { } }
-
Nevermind found the solution
-
Hello everyone.
I am trying to register my capability in my common proxy but my compiler can not resolve "register"
CapabilityManager.INSTANCE.register(IFatigue.class, new FatigueStorage(), Fatigue.class);
-
Is there an easy way to make an item replace itself in the players hand with another item?
Thanks in advance.
-
Hello everyone.
I made an item which changes its durabilitybar and enchantment glint depending on how often you rightclick.
Every instance of this item now has the same glint and durabilitybar even if their value is different on the server.
I think this is because I saved the values for the glint and durabilitybar method in my item class.
Because my NBTTagcompund is stuck in onItemRightClick.
What is the proper way of saving these values for every instance of my item?
Thanks in advance.
-
Just now, diesieben07 said:
That event handler method will never be called, @EventBusSubscriber only works for static event handler methods.
When are you calling setParticleTexture?It seems to work just fine now, thank you for your help.
[1.15.2] Items and blocks don't register correctly
in Modder Support
Posted
Ah ok it works now, but why shouldn't I use the ItemfromBlock method?