Jump to content

SaltStation

Members
  • Posts

    42
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by SaltStation

  1. Because all three blocks are the same except in name I made the following class:

    Spoiler
    
    public 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);
        }
    }

     

     

  2. I wanted to try the DeferredRegister to register items and blocks, but I always get this error:

     

    Quote

     Exception 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:

    Spoiler
    
    public 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!

  3. 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.

    1. When a lava lake is generated the ore is placed on nearby stone.
    2. 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?

     

     

  4. 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:

    https://github.com/SALTStation/mod/tree/master/src/main/java/com/SaltStation/Main/Capabilities/FatigueCapability

    https://github.com/SALTStation/mod/blob/master/src/main/java/com/SaltStation/Main/handlers/events/CapabilityHandeler.java

     

    Ignore wrong grammar...

     

  5. 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:

    Spoiler
    
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    player = server.getPlayerList().getPlayerByUUID(id);

     

    I want to get the statistcmanagerserver from the player by the way.

  6. 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.

    • Like 2
  7. 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:

    Spoiler

     

     

    
    public 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;
        }
    }

     

     

  8. 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;
        }

     

     

  9. 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:

    Spoiler
    
    
    public 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:

    Spoiler
    
    
    public 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:

    Spoiler
    
    
    public 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:

    Spoiler
    
    public 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:

    Spoiler
    
    public 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:

    Spoiler
    
    public 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) {
        }
    
    }

     

     

     

     

     

     

     

     

     

  10. 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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.