Jump to content

RekTek249

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by RekTek249

  1. Don't take this too seriously, but I'd go for the following method:

     

    @SubscribeEvent
        public void regiterItems(ProjectileImpactEvent event) {
            if (event.getRayTraceResult().typeOfHit == RayTraceResult.Type.BLOCK){
                //Destroy block here
            }
        }

    This would be the best event to go for, in my opinion.

     

    EDIT:

     

    For the block destruction, I'd try 

    event.getEntity().getEntityWorld().setBlockToAir(event.getRayTraceResult().getBlockPos());

    But I haven't tested it. I'm not even sure if event.getEntity() returns the player that shot the arrow....

  2. 5 minutes ago, Draco18s said:

    Do not use ForgeRegistries.ITEMS.register(rbsteak); directly. Use the registry events.

    The problem is that you likely did not register the class with the event bus correctly / at all.

    For example, my common proxy:

    Spoiler
    
    @Mod.EventBusSubscriber
    public abstract class CommonProxy {
    
        public void preInit() {
        }
    
        public void init() {
    
    
        }
    
        public void postInit(){
    
        }
    
        @SubscribeEvent
        public void registerItems(RegistryEvent.Register<Item> event) {
            event.getRegistry().register(RegisterItems.rbsteak);
        }
    
    
    
    
    }

    Would there be a problem in there ? It still won't work with your method. 

  3. 5 minutes ago, RekTek249 said:

    Alright, so I'm still not quite sure about how theses SubscribeEvent annotations... Your source code is quite long and seems to contain elements I do not need to use. I tried adding the following to my code: 

    CommonProxy.java

      Reveal hidden contents
    
    
    @SubscribeEvent
    public void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().register(RegisterItems.rbsteak);
    }

    ClientProxy.java

      Reveal hidden contents
    
    
    @SubscribeEvent
    public void registerModels(ModelRegistryEvent event) {
        ModelResourceLocation resLoc = new ModelResourceLocation("pmod:rbsteak", "inventory");
        ModelLoader.setCustomModelResourceLocation(rbsteak, 0, resLoc);
    
    }

     

    However, it would seem theses two are not even fired up. I'm sure there's something I should know but I don't know here...

    Actually, I managed to add it to the game using the following code in my previous function: 

    Spoiler
    
    public static void registerItems(){
            Item rbsteak = (SimpleItem)(new SimpleItem("Raid Boss Steak", "rbsteak", CreativeTabs.FOOD, 16));
            items.add(rbsteak);
            ForgeRegistries.ITEMS.register(rbsteak);
    //Would use a foreach loop here if it wasn't one single item
    
    }

    Is it correct to use this ? It seems to be working, but there might be a reason for you to use the @SubscribeEvent instead.

  4. 1 hour ago, Draco18s said:

    You're not actually registering any items or blocks:

    http://mcforge.readthedocs.io/en/latest/concepts/registries/#registering-things

    You will want to follow the same nomenclature for registering item models as well, using the ModelRegistryEvent inside your client proxy. e.g. like this (albeit my code takes in the data in a different way, storing it in an custom typed array, but still calling ModelLoader.setCustomModelResourceLocation from this method).

    Alright, so I'm still not quite sure about how theses SubscribeEvent annotations... Your source code is quite long and seems to contain elements I do not need to use. I tried adding the following to my code: 

    CommonProxy.java

    Spoiler
    
    @SubscribeEvent
    public void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().register(RegisterItems.rbsteak);
    }

    ClientProxy.java

    Spoiler
    
    @SubscribeEvent
    public void registerModels(ModelRegistryEvent event) {
        ModelResourceLocation resLoc = new ModelResourceLocation("pmod:rbsteak", "inventory");
        ModelLoader.setCustomModelResourceLocation(rbsteak, 0, resLoc);
    
    }

     

    However, it would seem theses two are not even fired up. I'm sure there's something I should know but I don't know here...

  5. Hi, so I just started out forge modding, with no prior knowledge of it. I have a good knowledge of java and have coded some plugins before, but this is my first time when it comes to modding. So, I'm trying to follow the official forge documentation. I kind of tried to register the item into the game, however it doesn't appear in the creative tab I set it to or using /give. Here is the code I have thus far: (Proxies are displayed in the same class, but they're not.

    Proxies:

    Spoiler
    
    //Proxies
    public class ClientProxy extends CommonProxy {
    
        public void preInit() {
            super.preInit();
            RegisterItems.registerItemModels();
            RegisterItems.registerBlockModels();
        }
    
        public void init() {
            super.init();
        }
    
        public void postInit(){
            super.postInit();
        }
    
    }
    public class ServerProxy extends CommonProxy {
    
        public void preInit() {
            super.preInit();
    
        }
    
        public void init() {
            super.init();
    
        }
    
        public void postInit(){
            super.postInit();
    
        }
    
    
    }
    public abstract class CommonProxy {
    
        public void preInit() {
            RegisterItems.registerBlocks();
            RegisterItems.registerItems();
    
        }
    
        public void init() {
    
    
        }
    
        public void postInit(){
    
        }
    
    
    }

     

    Main

    Spoiler
    
    @Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION)
    
    public class Main {
    
        public static final String MODID = "pmod";
        public static final String NAME = "Practice Mod";
        public static final String VERSION = "1.0";
    
    
        @SidedProxy(clientSide = "rektek249.practicemod.client.ClientProxy", serverSide = "rektek249.practicemod.server.ServerProxy")
        public static CommonProxy proxy;
    
    
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
            proxy.preInit();
        }
    
        @EventHandler
        public void init(FMLInitializationEvent event) {
            proxy.init();
    
        }
    
        @EventHandler
        public void postInit(FMLPostInitializationEvent event){
            proxy.postInit();
    
        }
    
    
    }

     

    RegisterItems.java

    Spoiler
    
    public class RegisterItems {
    
        static List<Item> items = new ArrayList<>();
        static List<Block> blocks = new ArrayList<>();
    
    
        public static void registerItems(){
                Item rbsteak = (SimpleItem)(new SimpleItem("Raid Boss Steak", "rbsteak", CreativeTabs.FOOD, 16));
                items.add(rbsteak);
                System.out.println("Items Registered");
        }
        public static void registerBlocks(){
    
        }
        public static void registerItemModels(){
    
            ModelResourceLocation resLoc;
            for(Item i : items){
                resLoc = new ModelResourceLocation("pmod:rbsteak", "inventory");
                ModelLoader.setCustomModelResourceLocation(i, 0, resLoc);
                System.out.println("One Model Registered");
            }
        }
        public static void registerBlockModels(){
    
        }
    
    }

     

    SimpleItem.java

    Spoiler
    
    public class SimpleItem extends Item {
    
        public SimpleItem(String unlocalizedName, String registryName, CreativeTabs tab){
    
            this.setUnlocalizedName(unlocalizedName);
            this.setRegistryName(registryName);
            this.setCreativeTab(tab);
    
    
        }
        public SimpleItem(String unlocalizedName, String registryName){
    
            this.setUnlocalizedName(unlocalizedName);
            this.setRegistryName(registryName);
    
        }
        public SimpleItem(String unlocalizedName, String registryName, CreativeTabs tab, int stackSize){
    
            this.setUnlocalizedName(unlocalizedName);
            this.setRegistryName(registryName);
            this.setCreativeTab(tab);
            this.setMaxStackSize(stackSize);
    
    
        }
        public SimpleItem(String unlocalizedName, String registryName, int stackSize){
    
            this.setUnlocalizedName(unlocalizedName);
            this.setRegistryName(registryName);
            this.setMaxStackSize(stackSize);
    
    
        }
    
    
    
    }

     

    So, am I missing something out there ? I tried to follow the documentation's recommendation as to proxies, server/client side stuff. Apparently I should have used an Interface for CommonProxy but I thought an abstract class would be a better choice. If you find any other issues in the code, don't hesitate to let me know.

×
×
  • Create New...

Important Information

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