Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.examplemod;
- import net.minecraft.block.Block;
- import net.minecraft.block.Block.Properties;
- import net.minecraft.block.Blocks;
- import net.minecraft.block.SlabBlock;
- import net.minecraft.block.StairsBlock;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.entity.EntityRenderer;
- import net.minecraft.client.renderer.entity.SpriteRenderer;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityType;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.item.BlockItem;
- import net.minecraft.item.Food;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemGroup;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.Items;
- import net.minecraft.nbt.CompoundNBT;
- import net.minecraft.potion.Effect;
- import net.minecraft.potion.EffectInstance;
- import net.minecraft.potion.EffectType;
- import net.minecraft.potion.Effects;
- import net.minecraft.potion.Potion;
- import net.minecraft.tags.ItemTags;
- import net.minecraft.util.ResourceLocation;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.common.ToolType;
- import net.minecraftforge.event.RegistryEvent;
- import net.minecraftforge.event.TickEvent;
- import net.minecraftforge.event.TickEvent.PlayerTickEvent;
- import net.minecraftforge.event.TickEvent.WorldTickEvent;
- import net.minecraftforge.event.world.BlockEvent;
- import net.minecraftforge.event.world.BlockEvent.BreakEvent;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.fml.client.registry.RenderingRegistry;
- import net.minecraftforge.fml.common.Mod;
- import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
- import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
- import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
- import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
- import java.util.Collection;
- import java.util.HashSet;
- import java.util.Set;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import com.example.examplemod.effectsregistry.ChlorinePoisoning;
- import com.example.examplemod.effectsregistry.EffectList;
- import com.example.examplemod.effectsregistry.FullOfOxygen;
- import com.example.examplemod.entityregistry.EntityList;
- import com.example.examplemod.entityregistry.parentclasses.Missle;
- import com.example.examplemod.food.FoodList;
- import com.example.examplemod.itemgroups.AtomModGases;
- import com.example.examplemod.itemgroups.AtomModMaterials;
- import com.example.examplemod.itemtags.TagList;
- import com.example.examplemod.registerall.blockregistry.BlockList;
- import com.example.examplemod.registerall.blockregistry.ozonegas;
- import com.example.examplemod.registerall.blockregistry.parent.StairsBlockAtom;
- import com.example.examplemod.registerall.itemregistry.ItemList;
- import com.example.examplemod.registerall.itemregistry.itemparentclass.DrinkableItem;
- import com.example.examplemod.registerall.itemregistry.itemparentclass.GrenadeItem;
- // The value here should match an entry in the META-INF/mods.toml file
- @Mod("atommod")
- public class ExampleMod
- {
- //help variables
- public final static String modid = "atommod";
- // Directly reference a log4j logger.
- public static final Logger Log = LogManager.getLogger();
- //itemgroups
- public static ItemGroup Gases = new AtomModGases();
- public static ItemGroup Materials = new AtomModMaterials();
- public ExampleMod()
- {
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
- MinecraftForge.EVENT_BUS.register(this);
- MinecraftForge.EVENT_BUS.register(EventHandler.class);
- }
- public void clientRegistries(final FMLClientSetupEvent event)
- {
- Log.info("client registries ready");
- RenderingRegistry.registerEntityRenderingHandler(Missle.class, a-> new SpriteRenderer</*either T or nothing here, not sure*/>(a, Minecraft.getInstance().getItemRenderer()));
- }
- private void setup(final FMLCommonSetupEvent event)
- {
- Log.info("Atommod says: hello from preinit guys!");
- }
- @Mod.EventBusSubscriber(bus =Mod.EventBusSubscriber.Bus.MOD)
- public static class RegistryEvents
- {
- @SubscribeEvent
- public static void registerEffects(final RegistryEvent.Register<Effect> event)
- {
- event.getRegistry().registerAll
- (
- EffectList.ChlorinePoisoning.setRegistryName("chlorine"),
- EffectList.FullOfOxygen.setRegistryName("oxygen")
- );
- }
- @SubscribeEvent
- //itemregister
- public static void registerItems(final RegistryEvent.Register<Item> event)
- {
- Item.Properties gases = new Item.Properties().group(Gases).maxStackSize(1);
- Item.Properties materials = new Item.Properties().group(Materials).maxStackSize(64);
- Item.Properties gases_drinkable = new Item.Properties().group(Gases).maxStackSize(1).containerItem(ItemList.glass_jar);
- Item.Properties rotten_food = new Item.Properties().group(ItemGroup.FOOD);
- Potion potionchlorine = new Potion(new EffectInstance(EffectList.ChlorinePoisoning,4*20,1));
- event.getRegistry().registerAll
- (
- //gases
- ItemList.oxygen_jar = new DrinkableItem(gases_drinkable,EffectList.FullOfOxygen,10).setRegistryName(location("jar_oxygen")),
- ItemList.ozone_jar = new Item(gases).setRegistryName(location("jar_ozone")),
- ItemList.radon_jar = new Item(gases).setRegistryName(location("jar_radon")),
- ItemList.chlorine_jar = new DrinkableItem(gases_drinkable,EffectList.ChlorinePoisoning,4).setRegistryName(location("jar_chlorine")),
- ItemList.oxygen_vial = new Item(gases).setRegistryName(location("vial_oxygen")),
- ItemList.ozone_vial = new Item(gases).setRegistryName(location("vial_ozone")),
- ItemList.radon_vial = new Item(gases).setRegistryName(location("vial_radon")),
- ItemList.chlorine_vial = new GrenadeItem(gases, potionchlorine).setRegistryName(location("vial_chlorine")),
- ItemList.glass_jar.setRegistryName(location("jar_air")),
- ItemList.glass_vial = new Item(gases).setRegistryName(location("vial_air")),
- ItemList.mix_jar = new Item(gases).setRegistryName(location("jar_mixed")),
- ItemList.mix_vial = new Item(gases).setRegistryName(location("vial_mixed")),
- //materials
- //items
- ItemList.obsidian_fiber = new Item(materials).setRegistryName(location("fiber_obsidian")),
- //blocks
- ItemList.obsidian_fabric = new BlockItem(BlockList.obsidian_fabric, materials).setRegistryName(location("fabric_obsidian")),
- ItemList.reinforced_stone = new BlockItem(BlockList.reinforced_stone, materials).setRegistryName(location("reinforced_stone")),
- ItemList.hardened_stone_wall = new BlockItem(BlockList.hardened_stone_wall, materials).setRegistryName(location("hardened_wall")),
- ItemList.lab_bricks = new BlockItem(BlockList.lab_bricks, materials).setRegistryName(location("bricks_lab")),
- ItemList.lab_bricks_stairs = new BlockItem(BlockList.lab_bricks_stairs, materials).setRegistryName(location("stairs_lab")),
- ItemList.lab_bricks_slab = new BlockItem(BlockList.lab_bricks_slab, materials).setRegistryName(location("slab_lab")),
- //rotten food
- ItemList.wormy_apple = new Item(rotten_food.food(FoodList.wormy_apple)).setRegistryName("wormy_apple"),
- ItemList.rotten_apple = new Item(rotten_food.food(FoodList.rotten_apple)).setRegistryName("rotten_apple"),
- ItemList.poisonous_beetroot = new Item(rotten_food.food(FoodList.poisonous_beetroot)).setRegistryName("poisonous_beetroot"),
- ItemList.rotten_beetroot = new Item(rotten_food.food(FoodList.rotten_beetroot)).setRegistryName("rotten_beetroot"),
- ItemList.poisonous_carrot = new Item(rotten_food.food(FoodList.poisonous_carrot)).setRegistryName("poisonous_carrot"),
- ItemList.rotten_carrot = new Item(rotten_food.food(FoodList.rotten_carrot)).setRegistryName("rotten_carrot"),
- ItemList.expired_beetroot_soup = new Item(rotten_food.food(FoodList.expired_soup).maxStackSize(1).containerItem(Items.BOWL)).setRegistryName("expired_beetroot_soup"),
- ItemList.expired_mushroom_stew = new Item(rotten_food.food(FoodList.expired_soup).maxStackSize(1).containerItem(Items.BOWL)).setRegistryName("expired_mushroom_stew"),
- ItemList.poisonous_berries = new Item(rotten_food.food(FoodList.poisonous_berries)).setRegistryName("poisonous_berries"),
- ItemList.rotten_berries = new Item(rotten_food.food(FoodList.rotten_berries)).setRegistryName("rotten_berries"),
- ItemList.rotten_potato = new Item(rotten_food.food(FoodList.rotten_potato)).setRegistryName("rotten_potato")
- );
- Log.info("Guys we did it! Items registered");
- }
- @SubscribeEvent
- //blockregister
- public static void registerBlocks(final RegistryEvent.Register<Block> event)
- {
- event.getRegistry().registerAll
- (
- //gases
- BlockList.ozonegas = new ozonegas(Block.Properties.create(Material.AIR).doesNotBlockMovement().noDrops()).setRegistryName(location("ozonegas")),
- //solid blocks
- BlockList.obsidian_fabric = new Block(Block.Properties.create(Material.WOOL).hardnessAndResistance(3.0f,20.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("fabric_obsidian")),
- BlockList.reinforced_stone = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.5f,40.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("reinforced_stone")),
- BlockList.hardened_stone_wall = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(4.0f,40.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("hardened_wall")),
- BlockList.lab_bricks = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(5.0f,21000.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("bricks_lab")),
- BlockList.lab_bricks_stairs = new StairsBlockAtom(BlockList.lab_bricks.getDefaultState(),Block.Properties.from(BlockList.lab_bricks)).setRegistryName(location("stairs_lab")),
- BlockList.lab_bricks_slab = new SlabBlock(Block.Properties.from(BlockList.lab_bricks)).setRegistryName(location("slab_lab"))
- );
- Log.info("Guys we did it! Blocks registered");
- }
- @SubscribeEvent
- public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event)
- {
- event.getRegistry().registerAll
- (
- EntityList.MISSLE.setRegistryName(location("missle"))
- );
- Log.info("Guys we did it! Entities registered");
- }
- //resourcelocation function
- public static ResourceLocation location(String name)
- {
- return new ResourceLocation(modid,name);
- }
- }
- //event handler
- @Mod.EventBusSubscriber
- public static class EventHandler
- {
- @SubscribeEvent
- public static void onBlockBroken(BreakEvent event)
- {
- PlayerEntity player = event.getPlayer();
- ResourceLocation[] location;
- location = new ResourceLocation[2];
- location[0] = RegistryEvents.location("fiber_obsidian");
- location[1] = RegistryEvents.location("fabric_obsidian");
- if
- (event.getState() == Blocks.OBSIDIAN.getDefaultState())
- {
- player.unlockRecipes(location);
- }
- }
- @SubscribeEvent
- public static void onPlayerTick(PlayerTickEvent event)
- {
- PlayerEntity player = event.player;
- //unlocking recipes
- ResourceLocation[] location;
- location = new ResourceLocation[2];
- location[0] = RegistryEvents.location("reinforced_stone_one");
- location[1] = RegistryEvents.location("reinforced_stone_two");
- Set<Item> set = new HashSet<Item>();
- set.add(Items.STONE);
- if(player.inventory.hasAny(set))
- {
- player.unlockRecipes(location);
- }
- ResourceLocation[] location1;
- location1 = new ResourceLocation[1];
- location1[0] = RegistryEvents.location("smelting_reinforced_stone");
- Set<Item> set1 = new HashSet<Item>();
- set1.add(ItemList.reinforced_stone);
- if(player.inventory.hasAny(set1))
- {
- player.unlockRecipes(location1);
- }
- ResourceLocation[] location2;
- location2 = new ResourceLocation[2];
- location2[0] = RegistryEvents.location("lab_bricks_one");
- location2[1] = RegistryEvents.location("lab_bricks_two");
- Set<Item> set2 = new HashSet<Item>();
- set2.add(ItemList.hardened_stone_wall);
- if(player.inventory.hasAny(set2))
- {
- player.unlockRecipes(location2);
- }
- ResourceLocation[] location3;
- location3 = new ResourceLocation[3];
- location3[0] = RegistryEvents.location("slab_lab");
- location3[1] = RegistryEvents.location("stairs_lab_one");
- location3[2] = RegistryEvents.location("stairs_lab_two");
- Set<Item> set3 = new HashSet<Item>();
- set3.add(ItemList.lab_bricks);
- if(player.inventory.hasAny(set3))
- {
- player.unlockRecipes(location3);
- }
- //end of recipes unlocking
- int minutes = 3;
- for(int i = 0; i < player.inventory.mainInventory.size(); i++)
- {
- ItemStack itemstack = player.inventory.mainInventory.get(i);
- if(TagList.FOOD_ITEMS.contains(itemstack.getItem()))
- {
- CompoundNBT rottingData = itemstack.getOrCreateChildTag("Rotting");
- int number = 0;
- if(number <= 1)
- {
- number = rottingData.getInt("ShelfLifeRemaining");
- }
- rottingData.putInt("ShelfLifeRemaining", number+1);
- if(rottingData.getInt("ShelfLifeRemaining") == minutes*60*20)
- {
- if(itemstack.getItem() == Items.BEETROOT)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_beetroot,itemstack.getCount()));
- }
- else if(itemstack.getItem() == ItemList.poisonous_beetroot)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_beetroot,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.CARROT)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_carrot,itemstack.getCount()));
- }
- else if(itemstack.getItem() == ItemList.poisonous_carrot)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_carrot,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.APPLE)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.wormy_apple,itemstack.getCount()));
- }
- else if(itemstack.getItem() == ItemList.wormy_apple)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_apple,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.POTATO)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(Items.POISONOUS_POTATO,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.POISONOUS_POTATO)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_potato,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.SWEET_BERRIES)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_berries,itemstack.getCount()));
- }
- else if(itemstack.getItem() == ItemList.poisonous_berries)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_berries,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.BEETROOT_SOUP)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.expired_beetroot_soup,itemstack.getCount()));
- }
- else if(itemstack.getItem() == Items.MUSHROOM_STEW)
- {
- player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.expired_mushroom_stew,itemstack.getCount()));
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement