Jump to content

PadFoot2008

Members
  • Posts

    43
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

PadFoot2008's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Thanks for replying. It does work except I can't seem to knock them back away from the player, instead they get pulled towards the player and stay at the player's location and when I switch to another item they get thrown away. How do I knock them back away from the player?
  2. Also what I'm trying to do is that holding this particular staff I made would cause Zombies to stay away from the player an eight block radius and any Zombies that're coming towards the player to attack them will quickly go out the radius as soon as the player brings the staff into their main hand. Could you also suggest a way to make that happen?
  3. Thanks for the help. But I tried doing that but it isn't work. In fact, for some reason, none of the event classes or mixins added by me seem to work. Could there be a specific reason for that? Also adding breakpoints doesn't work too. It did use to work, but it suddenly stopped working. I've also been getting java.io.IOException each time I run the mod. Just for extra info, I'm using IntelliJ IDE.
  4. I'm trying to make a potion which when applied to a zombie will cause it to run away from the player till the effect is over, kind of like how skeletons run away from wolves. But I have currently no idea how do make the zombie do that. Is there a way to do that?
  5. Edited - Actually I think I've already done that in the line before the class declaration. @Mod.EventBusSubscriber(modid = ImmersiveSurvival.MOD_ID) And also in the Mod class. MinecraftForge.EVENT_BUS.register(ModEvents.class); But it's still not working, please please help.
  6. I tried to create an event class which shall check if a player is holding a torch and make zombies and skeleton scared of the player an run away, but IntelliJ is telling me that Class 'ModEvents' is never used and Method 'onPlayerTick(net.minecraftforge.event.TickEvent.PlayerTickEvent)' is never used and both the class name and the method name appear grayed out instead of yellow. I don't understand where I went wrong. Please help and do tell me if I need to provide any other pieces of my mod. @Mod.EventBusSubscriber(modid = ImmersiveSurvival.MOD_ID) public class ModEvents { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.side == LogicalSide.CLIENT && event.phase == TickEvent.Phase.END) { PlayerEntity player = event.player; if (player.getHeldItemMainhand().getItem() == Items.TORCH) { World world = player.world; AxisAlignedBB box = player.getBoundingBox().grow(8.0); List<MobEntity> mobs = world.getEntitiesWithinAABB(MobEntity.class, box); for (MobEntity mob : mobs) { if (!mob.isPotionActive(FEAR_EFFECT) && (mob instanceof ZombieEntity || mob instanceof SkeletonEntity)) { mob.addPotionEffect(new EffectInstance(FEAR_EFFECT, 20)); mob.setRevengeTarget(player); } } } World world = player.world; AxisAlignedBB box = player.getBoundingBox().grow(128.0); for (Entity entity : world.getLoadedEntitiesWithinAABB(MobEntity.class, box)) { if (entity instanceof LivingEntity) { LivingEntity livingEntity = (LivingEntity) entity; if ((livingEntity instanceof ZombieEntity || livingEntity instanceof SkeletonEntity) && livingEntity.isPotionActive(FEAR_EFFECT)) { if (livingEntity.getActivePotionEffect(FEAR_EFFECT).getDuration() == 0) { livingEntity.setRevengeTarget(null); } } } } } } } Also, I created a Fear_Effect which doesnt really do anything except set a countdown so that I can set the target back to null. Please suggest a better way if you know one.
  7. Thanks a lot, the debugger method worked. It turns out that ItemStack#isEnchantible() returns false if the item already has an enchantment. So I removed it.
  8. Sorry if I sound like a novice, but how do I use debugger here (I'm not sure how to use debugger here)?
  9. In EnchantingPedestralTile.java, in the craft method, I changed ItemStack tool = iRecipe.getRecipeOutput(); to ItemStack tool = iRecipe.getCraftingResult(inv); And it works. It enchants the item and all but here, @Override public ItemStack getCraftingResult(IInventory inv) { ItemStack output = inv.getStackInSlot(0); int i = EnchantmentHelper.getEnchantmentLevel(enchant, output); int j = enchant.getMaxLevel(); if (output.isEnchantable() == true) { if (i != j) { output.addEnchantment(enchant, i + 1); } } return output; } It always enchants with level 1 enchantment, instead of getting the current enchantment level and incrementing it by one and then applying it to the item. Why does this happen? What do I do?
  10. Current code: public class EnchantingPedestralRecipe implements IEnchantingPedestralRecipe { public enum Weather { CLEAR, RAIN, THUNDERING; public static Weather getWeatherByString(String s) { return Objects.equals(s, "thundering") ? THUNDERING : Objects.equals(s, "rain") ? RAIN : CLEAR; } } private final ResourceLocation id; private final NonNullList<Ingredient> recipeItems; private final Weather weather; private final Enchantment enchant; public EnchantingPedestralRecipe(ResourceLocation id, NonNullList<Ingredient> recipeItems, Weather weather, Enchantment enchant) { this.id = id; this.recipeItems = recipeItems; this.weather = weather; this.enchant = enchant; } @Override public boolean matches(IInventory inv, World worldIn) { if (recipeItems.get(1).test(inv.getStackInSlot(1))) { return recipeItems.get(1).test(inv.getStackInSlot(1)); } return false; } @Override public NonNullList<Ingredient> getIngredients() { return recipeItems; } @Override public ItemStack getCraftingResult(IInventory inv) { ItemStack output = inv.getStackInSlot(0); int i = EnchantmentHelper.getEnchantmentLevel(enchant, output); int j = enchant.getMaxLevel(); int k = i++; if (output.isEnchantable() == true) { if (i<j) { output.addEnchantment(enchant, k); } } return output; } @Override public ItemStack getRecipeOutput() { ItemStack output = ItemStack.EMPTY; return output.copy(); } public Enchantment getEnchant() { return enchant; } public Weather getWeather() { return this.weather; } public ItemStack getIcon() { return new ItemStack(ModBlocks.ENCHANTING_PEDESTRAL.get()); } @Override public ResourceLocation getId() { return id; } @Override public IRecipeSerializer<?> getSerializer() { return ModRecipeTypes.ENCHANTING_SERIALIZER.get(); } public static class EnchantingRecipeType implements IRecipeType<EnchantingPedestralRecipe> { @Override public String toString() { return EnchantingPedestralRecipe.TYPE_ID.toString(); } } public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EnchantingPedestralRecipe> { @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, inputs, Weather.getWeatherByString(weather), enchant); } @Nullable @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.read(buffer)); } Enchantment enchant = buffer.readRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS); return new EnchantingPedestralRecipe(recipeId, inputs, null, enchant); } @Override public void write(PacketBuffer buffer, EnchantingPedestralRecipe recipe) { buffer.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.write(buffer); } buffer.writeRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS, recipe.getEnchant()); } } } Please help.
  11. It doesn't work. Both. ItemStack output = ItemStack.EMPTY; //OR ItemStack output = new ItemStack(Items.BELL);
  12. What does something mean? Like anything? A bell like I used earlier?
  13. But this is a syntax error? In read method output's coming as red. public class EnchantingPedestralRecipe implements IEnchantingPedestralRecipe { public enum Weather { CLEAR, RAIN, THUNDERING; public static Weather getWeatherByString(String s) { return Objects.equals(s, "thundering") ? THUNDERING : Objects.equals(s, "rain") ? RAIN : CLEAR; } } private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> recipeItems; private final Weather weather; private final Enchantment enchant; public EnchantingPedestralRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems, Weather weather, Enchantment enchant) { this.id = id; this.output = output; this.recipeItems = recipeItems; this.weather = weather; this.enchant = enchant; } @Override public boolean matches(IInventory inv, World worldIn) { if (recipeItems.get(1).test(inv.getStackInSlot(1))) { return recipeItems.get(1).test(inv.getStackInSlot(1)); } return false; } @Override public NonNullList<Ingredient> getIngredients() { return recipeItems; } @Override public ItemStack getCraftingResult(IInventory inv) { ItemStack output = inv.getStackInSlot(0); int i = EnchantmentHelper.getEnchantmentLevel(enchant, output); int j = enchant.getMaxLevel(); int k = i++; if (output.isEnchantable() == true) { if (i<j) { output.addEnchantment(enchant, k); } } return output; } @Override public ItemStack getRecipeOutput() { return output.copy(); } public Enchantment getEnchant() { return enchant; } public Weather getWeather() { return this.weather; } public ItemStack getIcon() { return new ItemStack(ModBlocks.ENCHANTING_PEDESTRAL.get()); } @Override public ResourceLocation getId() { return id; } @Override public IRecipeSerializer<?> getSerializer() { return ModRecipeTypes.ENCHANTING_SERIALIZER.get(); } public static class EnchantingRecipeType implements IRecipeType<EnchantingPedestralRecipe> { @Override public String toString() { return EnchantingPedestralRecipe.TYPE_ID.toString(); } } public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EnchantingPedestralRecipe> { @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather), enchant); } @Nullable @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.read(buffer)); } ItemStack output = buffer.readItemStack(); Enchantment enchant = buffer.readRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS); return new EnchantingPedestralRecipe(recipeId, output, inputs, null, enchant); } @Override public void write(PacketBuffer buffer, EnchantingPedestralRecipe recipe) { buffer.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.write(buffer); } buffer.writeItemStack(recipe.getRecipeOutput(), false); buffer.writeRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS, recipe.getEnchant()); } } }
  14. It isn't working (see code): public class EnchantingPedestralRecipe implements IEnchantingPedestralRecipe { public enum Weather { CLEAR, RAIN, THUNDERING; public static Weather getWeatherByString(String s) { return Objects.equals(s, "thundering") ? THUNDERING : Objects.equals(s, "rain") ? RAIN : CLEAR; } } private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> recipeItems; private final Weather weather; private final Enchantment enchant; public EnchantingPedestralRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems, Weather weather, Enchantment enchant) { this.id = id; this.output = output; this.recipeItems = recipeItems; this.weather = weather; this.enchant = enchant; } @Override public boolean matches(IInventory inv, World worldIn) { if (recipeItems.get(1).test(inv.getStackInSlot(1))) { return recipeItems.get(1).test(inv.getStackInSlot(1)); } return false; } @Override public NonNullList<Ingredient> getIngredients() { return recipeItems; } @Override public ItemStack getCraftingResult(IInventory inv) { ItemStack output = inv.getStackInSlot(0); int i = EnchantmentHelper.getEnchantmentLevel(enchant, output); int j = enchant.getMaxLevel(); int k = i++; if (output.isEnchantable() == true) { if (i<j) { output.addEnchantment(enchant, k); } } return output; } @Override public ItemStack getRecipeOutput() { return output.copy(); } public Enchantment getEnchant() { return enchant; } public Weather getWeather() { return this.weather; } public ItemStack getIcon() { return new ItemStack(ModBlocks.ENCHANTING_PEDESTRAL.get()); } @Override public ResourceLocation getId() { return id; } @Override public IRecipeSerializer<?> getSerializer() { return ModRecipeTypes.ENCHANTING_SERIALIZER.get(); } public static class EnchantingRecipeType implements IRecipeType<EnchantingPedestralRecipe> { @Override public String toString() { return EnchantingPedestralRecipe.TYPE_ID.toString(); } } public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EnchantingPedestralRecipe> { @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); ItemStack output = null; //I know this is incorrect; what do I do? String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather), enchant); } @Nullable @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.read(buffer)); } ItemStack output = buffer.readItemStack(); Enchantment enchant = buffer.readRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS); return new EnchantingPedestralRecipe(recipeId, output, inputs, null, enchant); } @Override public void write(PacketBuffer buffer, EnchantingPedestralRecipe recipe) { buffer.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.write(buffer); } buffer.writeItemStack(recipe.getRecipeOutput(), false); buffer.writeRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS, recipe.getEnchant()); } } }
×
×
  • Create New...

Important Information

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