Guest User

Untitled

a guest
Jan 21st, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.85 KB | None | 0 0
  1. package mod.mcreator;
  2.  
  3. import net.minecraftforge.fml.relauncher.SideOnly;
  4. import net.minecraftforge.fml.relauncher.Side;
  5. import net.minecraftforge.fml.common.registry.GameRegistry;
  6. import net.minecraftforge.fml.common.registry.ForgeRegistries;
  7. import net.minecraftforge.fml.common.registry.EntityRegistry;
  8. import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
  9. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  10. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  11. import net.minecraftforge.fml.client.registry.RenderingRegistry;
  12.  
  13. import net.minecraft.world.World;
  14. import net.minecraft.util.math.MathHelper;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.util.SoundCategory;
  17. import net.minecraft.util.ResourceLocation;
  18. import net.minecraft.util.EnumHand;
  19. import net.minecraft.util.EnumActionResult;
  20. import net.minecraft.util.ActionResult;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.item.Item;
  23. import net.minecraft.item.EnumAction;
  24. import net.minecraft.init.Items;
  25. import net.minecraft.init.Enchantments;
  26. import net.minecraft.init.Blocks;
  27. import net.minecraft.entity.projectile.EntityTippedArrow;
  28. import net.minecraft.entity.projectile.EntityArrow;
  29. import net.minecraft.entity.player.EntityPlayer;
  30. import net.minecraft.entity.EntityLivingBase;
  31. import net.minecraft.entity.Entity;
  32. import net.minecraft.enchantment.EnchantmentHelper;
  33. import net.minecraft.creativetab.CreativeTabs;
  34. import net.minecraft.client.renderer.entity.RenderSnowball;
  35. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  36. import net.minecraft.client.Minecraft;
  37. import net.minecraft.block.Block;
  38.  
  39. import java.util.Random;
  40.  
  41. public class mcreator_etherealstaff {
  42.  
  43. public mcreator_etherealstaff() {
  44. }
  45.  
  46. public static Item block;
  47. public static Object instance;
  48.  
  49. public void load(FMLInitializationEvent event) {
  50. if (event.getSide() == Side.CLIENT) {
  51. Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
  52. .register(block, 0, new ModelResourceLocation("stafftest:etherealstaff", "inventory"));
  53. }
  54.  
  55. GameRegistry.addShapedRecipe(new ResourceLocation("stafftest:etherealstaff"), new ResourceLocation("custom"),
  56. new ItemStack(block, 1), new Object[]{" 2", " 4 ", "6 ", Character.valueOf('2'), Items.DIAMOND, Character.valueOf('4'),
  57. mcreator_diamondhandle.block, Character.valueOf('6'), mcreator_diamondhandle.block,});
  58. }
  59.  
  60. @SideOnly(Side.CLIENT)
  61. public void registerRenderers() {
  62. RenderingRegistry.registerEntityRenderingHandler(EntityArrowCustom.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(),
  63. new ItemStack(Blocks.STONE_BUTTON).getItem(), Minecraft.getMinecraft().getRenderItem()));
  64. }
  65.  
  66. public void generateNether(World world, Random random, int chunkX, int chunkZ) {
  67. }
  68.  
  69. public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
  70. }
  71.  
  72. public int addFuel(ItemStack fuel) {
  73. return 0;
  74. }
  75.  
  76. public void serverLoad(FMLServerStartingEvent event) {
  77. }
  78.  
  79. public void preInit(FMLPreInitializationEvent event) {
  80. int entityID = MathHelper.getRandomUUID().hashCode();
  81. EntityRegistry.registerModEntity(new ResourceLocation("stafftest:entitybulletetherealstaff"), EntityArrowCustom.class,
  82. "entitybulletetherealstaff", entityID, instance, 64, 1, true);
  83. ForgeRegistries.ITEMS.register(block);
  84. }
  85.  
  86. static {
  87. block = (new ItemgGUN());
  88. }
  89.  
  90. static class ItemgGUN extends Item {
  91.  
  92. public ItemgGUN() {
  93. super();
  94. setMaxDamage(100);
  95. maxStackSize = 1;
  96. setFull3D();
  97. setUnlocalizedName("etherealstaff");
  98. setRegistryName("etherealstaff");
  99. setCreativeTab(CreativeTabs.COMBAT);
  100. }
  101.  
  102. @Override
  103. public int getMaxItemUseDuration(ItemStack par1ItemStack) {
  104. return 72000;
  105. }
  106.  
  107. @Override
  108. public ActionResult<ItemStack> onItemRightClick(World par2World, final EntityPlayer par3EntityPlayer, EnumHand hand) {
  109.  
  110. par3EntityPlayer.setActiveHand(hand);
  111.  
  112. ItemStack par1ItemStack = par3EntityPlayer.getHeldItem(hand);
  113.  
  114. boolean flag = par3EntityPlayer.capabilities.isCreativeMode
  115. || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, par1ItemStack) > 0;
  116.  
  117. if (flag || par3EntityPlayer.inventory.hasItemStack(new ItemStack(Blocks.AIR))) {
  118. float f = 1.0F;
  119.  
  120. EntityArrowCustom entityarrow = new EntityArrowCustom(par2World, par3EntityPlayer);
  121.  
  122. entityarrow.setThrowableHeading(par3EntityPlayer.getLookVec().x, par3EntityPlayer.getLookVec().y, par3EntityPlayer.getLookVec().z,
  123. f * 2.0F, 0);
  124. entityarrow.setIsCritical(true);
  125. entityarrow.setDamage(3.9999999999999996);
  126. entityarrow.setKnockbackStrength(1);
  127.  
  128. if (false) {
  129. entityarrow.setFire(100);
  130. }
  131.  
  132. par1ItemStack.damageItem(1, par3EntityPlayer);
  133. int i = (int) par3EntityPlayer.posX;
  134. int j = (int) par3EntityPlayer.posY;
  135. int k = (int) par3EntityPlayer.posZ;
  136. par2World.playSound((EntityPlayer) null, (double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D,
  137. (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY
  138. .getObject(new ResourceLocation(("entity.arrow.shoot"))), SoundCategory.NEUTRAL, 1.0F, 1.0F
  139. / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  140.  
  141. if (flag) {
  142. entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
  143. } else {
  144. par3EntityPlayer.inventory.clearMatchingItems(new ItemStack(Blocks.AIR).getItem(), -1, 1, null);
  145. }
  146.  
  147. if (!par2World.isRemote) {
  148. par2World.spawnEntity(entityarrow);
  149. }
  150. World world = par2World;
  151. EntityPlayer entity = par3EntityPlayer;
  152.  
  153. if (true) {
  154. world.playSound((EntityPlayer) null, (double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D,
  155. (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(
  156. ("stafftest:Wand sound"))), SoundCategory.NEUTRAL, 1.0F, 1.0F);
  157. }
  158.  
  159. if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == mcreator_etherealstaff.block) {
  160. itemstack.damageItem(1, entity);
  161. }
  162.  
  163. }
  164.  
  165. return new ActionResult(EnumActionResult.SUCCESS, par1ItemStack);
  166. }
  167.  
  168. @Override
  169. public EnumAction getItemUseAction(ItemStack par1ItemStack) {
  170. return EnumAction.BOW;
  171. }
  172.  
  173. }
  174.  
  175. public static class EntityArrowCustom extends EntityTippedArrow {
  176. public EntityArrowCustom(World a) {
  177. super(a);
  178. }
  179.  
  180. public EntityArrowCustom(World worldIn, double x, double y, double z) {
  181. super(worldIn, x, y, z);
  182. }
  183.  
  184. public EntityArrowCustom(World worldIn, EntityLivingBase shooter) {
  185. super(worldIn, shooter);
  186. }
  187.  
  188. @Override
  189. public void onCollideWithPlayer(EntityPlayer entity) {
  190. super.onCollideWithPlayer(entity);
  191. int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
  192. int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
  193. int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
  194. World world = this.world;
  195.  
  196. }
  197.  
  198. @Override
  199. public void onUpdate() {
  200. super.onUpdate();
  201. int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
  202. int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
  203. int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
  204. World world = this.world;
  205. Entity entity = (Entity) shootingEntity;
  206.  
  207. if (getBlock(this.world, i, j, k) != Blocks.AIR || getBlock(this.world, i, j - 1, k) != Blocks.AIR
  208. || getBlock(this.world, i, j + 1, k) != Blocks.AIR || getBlock(this.world, i + 1, j, k) != Blocks.AIR
  209. || getBlock(this.world, i - 1, j, k) != Blocks.AIR || getBlock(this.world, i, j, k + 1) != Blocks.AIR
  210. || getBlock(this.world, i, j, k - 1) != Blocks.AIR) {
  211.  
  212. this.world.removeEntity(this);
  213. }
  214.  
  215. }
  216.  
  217. public Block getBlock(World par1World, int i, int j, int k) {
  218. return par1World.getBlockState(new BlockPos(i, j, k)).getBlock();
  219. }
  220.  
  221. }
  222.  
  223. }
Advertisement
Add Comment
Please, Sign In to add comment