I've been using minecraft forge 1.12 to make a mod that gives the user super-jumping abilities. However, I've been having trouble making the player invincible to fall damage. I've tried to use a LivingFallEvent
like this:
@SubscribeEvent
public void onEntityFall(LivingFallEvent event)
{
event.setDistance(0.0F);
event.setCanceled(true);
}
but the player still gets damage from falling. What did I do wrong?
If you need it, here is my full code:
package com.blockmaster6678.totalweirdmod;
import java.util.List;
import com.blockmaster6678.totalweirdmod.init.ModBlocks;
import com.blockmaster6678.totalweirdmod.init.ModItems;
import com.blockmaster6678.totalweirdmod.money.MoneyWorth;
import com.blockmaster6678.totalweirdmod.money.PlayerMoney;
import com.blockmaster6678.totalweirdmod.proxy.CommonProxy;
import com.blockmaster6678.totalweirdmod.util.Attributes;
import com.google.common.collect.Multimap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayer.Position;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = Attributes.ID, name = Attributes.NAME, version = Attributes.VERSION)
public class Main {
private static boolean helped = false;
@Instance
public static Main instance;
@SidedProxy(clientSide = Attributes.CLIENT_PROXY_CLASS, serverSide = Attributes.COMMON_PROXY_CLASS)
public static CommonProxy proxy;
@EventHandler
public static void PreInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new Object() {
@SubscribeEvent
public void yourPlayerHarvestEvent(HarvestDropsEvent event) {
if (event.getHarvester() != null) {
if (event.getState() == ModBlocks.IVY_BLOCK.getDefaultState()) {
event.setDropChance(0.99F);
event.getDrops().add(new ItemStack(Item.getItemFromBlock(ModBlocks.IVY_BLOCK), 20));
event.getDrops().add(new ItemStack(Items.FIREWORKS, 32));
} else if (event.getState() == Blocks.DIRT.getDefaultState()) {
event.setDropChance(1.0F);
event.getDrops().add(new ItemStack(Item.getItemFromBlock(Blocks.DIRT), 64));
event.getDrops().add(new ItemStack(Item.getItemFromBlock(Blocks.CHORUS_FLOWER), 1));
event.getDrops().add(new ItemStack(Item.getItemFromBlock(Blocks.CACTUS), 2));
event.getDrops().add(new ItemStack(Item.getItemFromBlock(Blocks.SAND), 16));
} else if (event.getState() == Blocks.CACTUS.getDefaultState()) {
event.setDropChance(0.5F);
event.getDrops().clear();
event.getDrops().add(new ItemStack(Item.getItemFromBlock(Blocks.CACTUS), 2));
event.getDrops().add(new ItemStack(Items.BLAZE_ROD, 5));
event.getDrops().add(new ItemStack(Items.EXPERIENCE_BOTTLE, 64));
event.getDrops().add(new ItemStack(Items.BAKED_POTATO, 12));
event.getDrops().add(new ItemStack(Items.DIAMOND_SWORD, 1));
event.getDrops().add(new ItemStack(Items.APPLE, 49));
event.getDrops().add(new ItemStack(Items.ENDER_PEARL, 16));
event.getDrops().add(new ItemStack(Items.MAGMA_CREAM, 23));
event.getDrops().add(new ItemStack(Items.ELYTRA, 1));
Minecraft.getMinecraft().player.
addItemStackToInventory(new ItemStack(Item.getItemFromBlock(Blocks.CACTUS), 1));
} else if (event.getState() == Blocks.SAND.getDefaultState()) {
event.setDropChance(0.1F);
event.getDrops().add(new ItemStack(Items.ELYTRA, 1));
event.getDrops().add(new ItemStack(Item.getItemFromBlock(ModBlocks.IVY_BLOCK)));
}
}
}
});
}
@EventHandler
public static void init(FMLInitializationEvent event) {
}
@EventHandler
public static void Postinit(FMLPostInitializationEvent event) {
}
@EventHandler
public static void onPlayerInteract(PlayerInteractEvent event) {
EntityPlayer p = event.getEntityPlayer();
World world = p.getEntityWorld();
BlockPos pos = event.getPos();
if (!(p.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(ModBlocks.IVY_BLOCK)))) {
return;
}
world.setBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getX()), ModBlocks.IVY_BLOCK.getDefaultState());
}
@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
event.setDistance(0.0F);
event.setCanceled(true);
}
}