Started by
Maniacobra
on
Topic category: Help with Minecraft modding (Java Edition)
Hi, i'm very new to Forge, i'm trying to make the player bounce when he hits the ground with specific boots, similar to slime blocks. But I can't figure out what to do to make entity.setMotion work for Y motion, it works for X and Z axis but not Y.
The only condition where it can work is when I fall on a slime block, so I guess there's probably some methods to call to properly cancel the fall but I don't know these
Here's the code (i started from auto-generated code from a procedure and edited it after) :
package net.mcreator.ctfa.procedures;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.Entity;
import net.mcreator.ctfa.CtfaModElements;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;
@CtfaModElements.ModElement.Tag
public class SlimeBounceProcedure extends CtfaModElements.ModElement {
public SlimeBounceProcedure(CtfaModElements instance) {
super(instance, 18080);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
if (event != null && event.getEntity() != null) {
Entity entity = event.getEntity();
double i = entity.getPosX();
double j = entity.getPosY();
double k = entity.getPosZ();
double damagemultiplier = event.getDamageMultiplier();
double distance = event.getDistance();
World world = entity.world;
for (ItemStack itemStack : entity.getArmorInventoryList()) {
Item item = itemStack.getItem();
if (item.getRegistryName().toString().equals("ctfa:slime_block_armor_boots")) {
if (itemStack.attemptDamageItem((int)(distance * 0.6), new Random(), null)) {
itemStack.shrink(1);
itemStack.setDamage(0);
if (world instanceof World && !world.isRemote()) {
((World) world).playSound(null, new BlockPos((int) i, (int) j, (int) k),
(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.slime_block.break")),
SoundCategory.BLOCKS, 1.f, 1.f);
}
else {
((World) world).playSound(i, j, k,
(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.slime_block.break")),
SoundCategory.BLOCKS, 1.f, 1.f, false);
}
}
entity.setMotion(entity.getMotion().x, (int)(distance * 0.75), entity.getMotion().z);
entity.isAirBorne = true;
event.setCanceled(true);
if (world instanceof World && !world.isRemote()) {
((World) world).playSound(null, new BlockPos((int) i, (int) j, (int) k),
(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.slime_block.fall")),
SoundCategory.BLOCKS, 0.4f, 1.f);
}
else {
((World) world).playSound(i, j, k,
(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.slime_block.fall")),
SoundCategory.BLOCKS, 0.4f, 1.f, false);
}
}
}
}
}
}
This works using procedures but you only bounce from 16 block high
Event Trigger is set to player tick
Then use an if statement and put: Get item from armor slot "0" of "entity", and then put your "slime boots"
In the do part put: Override fall distance of "entity" with "0" blocks for the next tick, and under that put another if statement with an and gate with "Y velocity of "entity"" < "-0.7" and another and gate with a "not: is "entity" sneaking" and "not: Get block at "x" "y position of "entity" - "0.8"" "z" = (block) air"
In the second do part put: Attempt to override motion vector of "entity" to vx: "X velocity of "entity"" vy: "Y velocity of "entity" - "Y velocity of "entity" * "2"" vz: "Z velocity of "entity""
Download:
https://drive.google.com/file/d/1ytnDmr8d8WgSiUH0DBNmlk_rBj1fyPWu/view?usp=sharing
Just put the boots in the top item box