Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.49 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.Block.Properties;
  5. import net.minecraft.block.Blocks;
  6. import net.minecraft.block.SlabBlock;
  7. import net.minecraft.block.StairsBlock;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.client.renderer.entity.EntityRenderer;
  11. import net.minecraft.client.renderer.entity.SpriteRenderer;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.EntityType;
  14. import net.minecraft.entity.player.PlayerEntity;
  15. import net.minecraft.item.BlockItem;
  16. import net.minecraft.item.Food;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemGroup;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.item.Items;
  21. import net.minecraft.nbt.CompoundNBT;
  22. import net.minecraft.potion.Effect;
  23. import net.minecraft.potion.EffectInstance;
  24. import net.minecraft.potion.EffectType;
  25. import net.minecraft.potion.Effects;
  26. import net.minecraft.potion.Potion;
  27. import net.minecraft.tags.ItemTags;
  28. import net.minecraft.util.ResourceLocation;
  29. import net.minecraftforge.common.MinecraftForge;
  30. import net.minecraftforge.common.ToolType;
  31. import net.minecraftforge.event.RegistryEvent;
  32. import net.minecraftforge.event.TickEvent;
  33. import net.minecraftforge.event.TickEvent.PlayerTickEvent;
  34. import net.minecraftforge.event.TickEvent.WorldTickEvent;
  35. import net.minecraftforge.event.world.BlockEvent;
  36. import net.minecraftforge.event.world.BlockEvent.BreakEvent;
  37. import net.minecraftforge.eventbus.api.SubscribeEvent;
  38. import net.minecraftforge.fml.client.registry.RenderingRegistry;
  39. import net.minecraftforge.fml.common.Mod;
  40. import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
  41. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  42. import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
  43. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  44.  
  45. import java.util.Collection;
  46. import java.util.HashSet;
  47. import java.util.Set;
  48.  
  49. import org.apache.logging.log4j.LogManager;
  50. import org.apache.logging.log4j.Logger;
  51.  
  52. import com.example.examplemod.effectsregistry.ChlorinePoisoning;
  53. import com.example.examplemod.effectsregistry.EffectList;
  54. import com.example.examplemod.effectsregistry.FullOfOxygen;
  55. import com.example.examplemod.entityregistry.EntityList;
  56. import com.example.examplemod.entityregistry.parentclasses.Missle;
  57. import com.example.examplemod.food.FoodList;
  58. import com.example.examplemod.itemgroups.AtomModGases;
  59. import com.example.examplemod.itemgroups.AtomModMaterials;
  60. import com.example.examplemod.itemtags.TagList;
  61. import com.example.examplemod.registerall.blockregistry.BlockList;
  62. import com.example.examplemod.registerall.blockregistry.ozonegas;
  63. import com.example.examplemod.registerall.blockregistry.parent.StairsBlockAtom;
  64. import com.example.examplemod.registerall.itemregistry.ItemList;
  65. import com.example.examplemod.registerall.itemregistry.itemparentclass.DrinkableItem;
  66. import com.example.examplemod.registerall.itemregistry.itemparentclass.GrenadeItem;
  67.  
  68. // The value here should match an entry in the META-INF/mods.toml file
  69. @Mod("atommod")
  70. public class ExampleMod
  71. {
  72. //help variables
  73. public final static String modid = "atommod";
  74.  
  75.  
  76. // Directly reference a log4j logger.
  77. public static final Logger Log = LogManager.getLogger();
  78.  
  79.  
  80. //itemgroups
  81.  
  82. public static ItemGroup Gases = new AtomModGases();
  83. public static ItemGroup Materials = new AtomModMaterials();
  84.  
  85. public ExampleMod()
  86. {
  87.  
  88. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
  89.  
  90. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
  91.  
  92. MinecraftForge.EVENT_BUS.register(this);
  93. MinecraftForge.EVENT_BUS.register(EventHandler.class);
  94.  
  95. }
  96.  
  97. public void clientRegistries(final FMLClientSetupEvent event)
  98. {
  99. Log.info("client registries ready");
  100. RenderingRegistry.registerEntityRenderingHandler(Missle.class, a-> new SpriteRenderer</*either T or nothing here, not sure*/>(a, Minecraft.getInstance().getItemRenderer()));
  101. }
  102.  
  103. private void setup(final FMLCommonSetupEvent event)
  104. {
  105. Log.info("Atommod says: hello from preinit guys!");
  106. }
  107. @Mod.EventBusSubscriber(bus =Mod.EventBusSubscriber.Bus.MOD)
  108. public static class RegistryEvents
  109. {
  110.  
  111.  
  112. @SubscribeEvent
  113. public static void registerEffects(final RegistryEvent.Register<Effect> event)
  114. {
  115. event.getRegistry().registerAll
  116. (
  117. EffectList.ChlorinePoisoning.setRegistryName("chlorine"),
  118. EffectList.FullOfOxygen.setRegistryName("oxygen")
  119. );
  120. }
  121.  
  122. @SubscribeEvent
  123. //itemregister
  124. public static void registerItems(final RegistryEvent.Register<Item> event)
  125. {
  126. Item.Properties gases = new Item.Properties().group(Gases).maxStackSize(1);
  127. Item.Properties materials = new Item.Properties().group(Materials).maxStackSize(64);
  128. Item.Properties gases_drinkable = new Item.Properties().group(Gases).maxStackSize(1).containerItem(ItemList.glass_jar);
  129. Item.Properties rotten_food = new Item.Properties().group(ItemGroup.FOOD);
  130. Potion potionchlorine = new Potion(new EffectInstance(EffectList.ChlorinePoisoning,4*20,1));
  131. event.getRegistry().registerAll
  132. (
  133. //gases
  134.  
  135. ItemList.oxygen_jar = new DrinkableItem(gases_drinkable,EffectList.FullOfOxygen,10).setRegistryName(location("jar_oxygen")),
  136. ItemList.ozone_jar = new Item(gases).setRegistryName(location("jar_ozone")),
  137. ItemList.radon_jar = new Item(gases).setRegistryName(location("jar_radon")),
  138. ItemList.chlorine_jar = new DrinkableItem(gases_drinkable,EffectList.ChlorinePoisoning,4).setRegistryName(location("jar_chlorine")),
  139. ItemList.oxygen_vial = new Item(gases).setRegistryName(location("vial_oxygen")),
  140. ItemList.ozone_vial = new Item(gases).setRegistryName(location("vial_ozone")),
  141. ItemList.radon_vial = new Item(gases).setRegistryName(location("vial_radon")),
  142. ItemList.chlorine_vial = new GrenadeItem(gases, potionchlorine).setRegistryName(location("vial_chlorine")),
  143. ItemList.glass_jar.setRegistryName(location("jar_air")),
  144. ItemList.glass_vial = new Item(gases).setRegistryName(location("vial_air")),
  145. ItemList.mix_jar = new Item(gases).setRegistryName(location("jar_mixed")),
  146. ItemList.mix_vial = new Item(gases).setRegistryName(location("vial_mixed")),
  147. //materials
  148. //items
  149. ItemList.obsidian_fiber = new Item(materials).setRegistryName(location("fiber_obsidian")),
  150. //blocks
  151. ItemList.obsidian_fabric = new BlockItem(BlockList.obsidian_fabric, materials).setRegistryName(location("fabric_obsidian")),
  152. ItemList.reinforced_stone = new BlockItem(BlockList.reinforced_stone, materials).setRegistryName(location("reinforced_stone")),
  153. ItemList.hardened_stone_wall = new BlockItem(BlockList.hardened_stone_wall, materials).setRegistryName(location("hardened_wall")),
  154. ItemList.lab_bricks = new BlockItem(BlockList.lab_bricks, materials).setRegistryName(location("bricks_lab")),
  155. ItemList.lab_bricks_stairs = new BlockItem(BlockList.lab_bricks_stairs, materials).setRegistryName(location("stairs_lab")),
  156. ItemList.lab_bricks_slab = new BlockItem(BlockList.lab_bricks_slab, materials).setRegistryName(location("slab_lab")),
  157. //rotten food
  158. ItemList.wormy_apple = new Item(rotten_food.food(FoodList.wormy_apple)).setRegistryName("wormy_apple"),
  159. ItemList.rotten_apple = new Item(rotten_food.food(FoodList.rotten_apple)).setRegistryName("rotten_apple"),
  160. ItemList.poisonous_beetroot = new Item(rotten_food.food(FoodList.poisonous_beetroot)).setRegistryName("poisonous_beetroot"),
  161. ItemList.rotten_beetroot = new Item(rotten_food.food(FoodList.rotten_beetroot)).setRegistryName("rotten_beetroot"),
  162. ItemList.poisonous_carrot = new Item(rotten_food.food(FoodList.poisonous_carrot)).setRegistryName("poisonous_carrot"),
  163. ItemList.rotten_carrot = new Item(rotten_food.food(FoodList.rotten_carrot)).setRegistryName("rotten_carrot"),
  164. ItemList.expired_beetroot_soup = new Item(rotten_food.food(FoodList.expired_soup).maxStackSize(1).containerItem(Items.BOWL)).setRegistryName("expired_beetroot_soup"),
  165. ItemList.expired_mushroom_stew = new Item(rotten_food.food(FoodList.expired_soup).maxStackSize(1).containerItem(Items.BOWL)).setRegistryName("expired_mushroom_stew"),
  166. ItemList.poisonous_berries = new Item(rotten_food.food(FoodList.poisonous_berries)).setRegistryName("poisonous_berries"),
  167. ItemList.rotten_berries = new Item(rotten_food.food(FoodList.rotten_berries)).setRegistryName("rotten_berries"),
  168. ItemList.rotten_potato = new Item(rotten_food.food(FoodList.rotten_potato)).setRegistryName("rotten_potato")
  169.  
  170.  
  171.  
  172.  
  173. );
  174. Log.info("Guys we did it! Items registered");
  175. }
  176.  
  177. @SubscribeEvent
  178. //blockregister
  179. public static void registerBlocks(final RegistryEvent.Register<Block> event)
  180. {
  181. event.getRegistry().registerAll
  182. (
  183. //gases
  184. BlockList.ozonegas = new ozonegas(Block.Properties.create(Material.AIR).doesNotBlockMovement().noDrops()).setRegistryName(location("ozonegas")),
  185. //solid blocks
  186. BlockList.obsidian_fabric = new Block(Block.Properties.create(Material.WOOL).hardnessAndResistance(3.0f,20.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("fabric_obsidian")),
  187. BlockList.reinforced_stone = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.5f,40.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("reinforced_stone")),
  188. BlockList.hardened_stone_wall = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(4.0f,40.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("hardened_wall")),
  189. BlockList.lab_bricks = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(5.0f,21000.0f).harvestTool(ToolType.PICKAXE)).setRegistryName(location("bricks_lab")),
  190. BlockList.lab_bricks_stairs = new StairsBlockAtom(BlockList.lab_bricks.getDefaultState(),Block.Properties.from(BlockList.lab_bricks)).setRegistryName(location("stairs_lab")),
  191. BlockList.lab_bricks_slab = new SlabBlock(Block.Properties.from(BlockList.lab_bricks)).setRegistryName(location("slab_lab"))
  192. );
  193. Log.info("Guys we did it! Blocks registered");
  194. }
  195. @SubscribeEvent
  196. public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event)
  197. {
  198. event.getRegistry().registerAll
  199. (
  200. EntityList.MISSLE.setRegistryName(location("missle"))
  201.  
  202. );
  203. Log.info("Guys we did it! Entities registered");
  204. }
  205.  
  206. //resourcelocation function
  207. public static ResourceLocation location(String name)
  208. {
  209.  
  210. return new ResourceLocation(modid,name);
  211.  
  212. }
  213.  
  214. }
  215. //event handler
  216. @Mod.EventBusSubscriber
  217. public static class EventHandler
  218. {
  219.  
  220. @SubscribeEvent
  221. public static void onBlockBroken(BreakEvent event)
  222. {
  223. PlayerEntity player = event.getPlayer();
  224. ResourceLocation[] location;
  225. location = new ResourceLocation[2];
  226. location[0] = RegistryEvents.location("fiber_obsidian");
  227. location[1] = RegistryEvents.location("fabric_obsidian");
  228.  
  229. if
  230. (event.getState() == Blocks.OBSIDIAN.getDefaultState())
  231. {
  232. player.unlockRecipes(location);
  233. }
  234.  
  235.  
  236.  
  237. }
  238.  
  239. @SubscribeEvent
  240. public static void onPlayerTick(PlayerTickEvent event)
  241. {
  242. PlayerEntity player = event.player;
  243.  
  244. //unlocking recipes
  245. ResourceLocation[] location;
  246. location = new ResourceLocation[2];
  247. location[0] = RegistryEvents.location("reinforced_stone_one");
  248. location[1] = RegistryEvents.location("reinforced_stone_two");
  249. Set<Item> set = new HashSet<Item>();
  250. set.add(Items.STONE);
  251. if(player.inventory.hasAny(set))
  252. {
  253. player.unlockRecipes(location);
  254. }
  255.  
  256. ResourceLocation[] location1;
  257. location1 = new ResourceLocation[1];
  258. location1[0] = RegistryEvents.location("smelting_reinforced_stone");
  259. Set<Item> set1 = new HashSet<Item>();
  260. set1.add(ItemList.reinforced_stone);
  261. if(player.inventory.hasAny(set1))
  262. {
  263. player.unlockRecipes(location1);
  264. }
  265. ResourceLocation[] location2;
  266. location2 = new ResourceLocation[2];
  267. location2[0] = RegistryEvents.location("lab_bricks_one");
  268. location2[1] = RegistryEvents.location("lab_bricks_two");
  269. Set<Item> set2 = new HashSet<Item>();
  270. set2.add(ItemList.hardened_stone_wall);
  271. if(player.inventory.hasAny(set2))
  272. {
  273. player.unlockRecipes(location2);
  274. }
  275.  
  276. ResourceLocation[] location3;
  277. location3 = new ResourceLocation[3];
  278. location3[0] = RegistryEvents.location("slab_lab");
  279. location3[1] = RegistryEvents.location("stairs_lab_one");
  280. location3[2] = RegistryEvents.location("stairs_lab_two");
  281. Set<Item> set3 = new HashSet<Item>();
  282. set3.add(ItemList.lab_bricks);
  283. if(player.inventory.hasAny(set3))
  284. {
  285. player.unlockRecipes(location3);
  286. }
  287.  
  288. //end of recipes unlocking
  289. int minutes = 3;
  290. for(int i = 0; i < player.inventory.mainInventory.size(); i++)
  291. {
  292. ItemStack itemstack = player.inventory.mainInventory.get(i);
  293. if(TagList.FOOD_ITEMS.contains(itemstack.getItem()))
  294. {
  295. CompoundNBT rottingData = itemstack.getOrCreateChildTag("Rotting");
  296. int number = 0;
  297. if(number <= 1)
  298. {
  299. number = rottingData.getInt("ShelfLifeRemaining");
  300. }
  301. rottingData.putInt("ShelfLifeRemaining", number+1);
  302. if(rottingData.getInt("ShelfLifeRemaining") == minutes*60*20)
  303. {
  304.  
  305. if(itemstack.getItem() == Items.BEETROOT)
  306. {
  307. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_beetroot,itemstack.getCount()));
  308. }
  309. else if(itemstack.getItem() == ItemList.poisonous_beetroot)
  310. {
  311. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_beetroot,itemstack.getCount()));
  312. }
  313. else if(itemstack.getItem() == Items.CARROT)
  314. {
  315. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_carrot,itemstack.getCount()));
  316. }
  317. else if(itemstack.getItem() == ItemList.poisonous_carrot)
  318. {
  319. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_carrot,itemstack.getCount()));
  320. }
  321. else if(itemstack.getItem() == Items.APPLE)
  322. {
  323. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.wormy_apple,itemstack.getCount()));
  324. }
  325. else if(itemstack.getItem() == ItemList.wormy_apple)
  326. {
  327. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_apple,itemstack.getCount()));
  328. }
  329. else if(itemstack.getItem() == Items.POTATO)
  330. {
  331. player.inventory.setInventorySlotContents(i, new ItemStack(Items.POISONOUS_POTATO,itemstack.getCount()));
  332. }
  333. else if(itemstack.getItem() == Items.POISONOUS_POTATO)
  334. {
  335. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_potato,itemstack.getCount()));
  336. }
  337. else if(itemstack.getItem() == Items.SWEET_BERRIES)
  338. {
  339. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.poisonous_berries,itemstack.getCount()));
  340. }
  341. else if(itemstack.getItem() == ItemList.poisonous_berries)
  342. {
  343. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.rotten_berries,itemstack.getCount()));
  344. }
  345. else if(itemstack.getItem() == Items.BEETROOT_SOUP)
  346. {
  347. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.expired_beetroot_soup,itemstack.getCount()));
  348. }
  349. else if(itemstack.getItem() == Items.MUSHROOM_STEW)
  350. {
  351. player.inventory.setInventorySlotContents(i, new ItemStack(ItemList.expired_mushroom_stew,itemstack.getCount()));
  352. }
  353. }
  354. }
  355.  
  356. }
  357.  
  358.  
  359.  
  360.  
  361. }
  362.  
  363. }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement