Mortal Compat

- Commented a teleport hook not yet included in recommended forge
This commit is contained in:
simibubi 2021-07-07 22:05:09 +02:00
parent 10b0bdbfcf
commit 83a3faa871

View file

@ -36,11 +36,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.living.EntityTeleportEvent;
import net.minecraftforge.registries.IRegistryDelegate; import net.minecraftforge.registries.IRegistryDelegate;
public class PotatoCannonProjectileTypes { public class PotatoCannonProjectileTypes {
@ -116,7 +115,7 @@ public class PotatoCannonProjectileTypes {
.velocity(1.20f) .velocity(1.20f)
.knockback(0.05f) .knockback(0.05f)
.renderTumbling() .renderTumbling()
.onEntityHit(chorusTeleport(20)) .onEntityHitRecoveryCancelable(chorusTeleport(20))
.registerAndAssign(Items.CHORUS_FRUIT), .registerAndAssign(Items.CHORUS_FRUIT),
APPLE = create("apple").damage(5) APPLE = create("apple").damage(5)
@ -142,7 +141,7 @@ public class PotatoCannonProjectileTypes {
.knockback(0.05f) .knockback(0.05f)
.renderTumbling() .renderTumbling()
.soundPitch(1.1f) .soundPitch(1.1f)
.onEntityHit(foodEffects(Foods.GOLDEN_APPLE)) .onEntityHitRecoveryCancelable(foodEffects(Foods.GOLDEN_APPLE))
.registerAndAssign(Items.GOLDEN_APPLE), .registerAndAssign(Items.GOLDEN_APPLE),
ENCHANTED_GOLDEN_APPLE = create("enchanted_golden_apple").damage(1) ENCHANTED_GOLDEN_APPLE = create("enchanted_golden_apple").damage(1)
@ -151,7 +150,7 @@ public class PotatoCannonProjectileTypes {
.knockback(0.05f) .knockback(0.05f)
.renderTumbling() .renderTumbling()
.soundPitch(1.1f) .soundPitch(1.1f)
.onEntityHit(foodEffects(Foods.ENCHANTED_GOLDEN_APPLE)) .onEntityHitRecoveryCancelable(foodEffects(Foods.ENCHANTED_GOLDEN_APPLE))
.registerAndAssign(Items.ENCHANTED_GOLDEN_APPLE), .registerAndAssign(Items.ENCHANTED_GOLDEN_APPLE),
BEETROOT = create("beetroot").damage(2) BEETROOT = create("beetroot").damage(2)
@ -313,7 +312,7 @@ public class PotatoCannonProjectileTypes {
}; };
} }
private static Consumer<EntityRayTraceResult> foodEffects(Food food) { private static Predicate<EntityRayTraceResult> foodEffects(Food food) {
return ray -> { return ray -> {
Entity entity = ray.getEntity(); Entity entity = ray.getEntity();
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
@ -322,6 +321,7 @@ public class PotatoCannonProjectileTypes {
((LivingEntity) entity).addPotionEffect(effect.getFirst()); ((LivingEntity) entity).addPotionEffect(effect.getFirst());
} }
} }
return true;
}; };
} }
@ -377,14 +377,14 @@ public class PotatoCannonProjectileTypes {
}; };
} }
private static Consumer<EntityRayTraceResult> chorusTeleport(double teleportDiameter) { private static Predicate<EntityRayTraceResult> chorusTeleport(double teleportDiameter) {
return ray -> { return ray -> {
Entity entity = ray.getEntity(); Entity entity = ray.getEntity();
World world = entity.getEntityWorld(); World world = entity.getEntityWorld();
if (world.isRemote) if (world.isRemote)
return; return true;
if (!(entity instanceof LivingEntity)) if (!(entity instanceof LivingEntity))
return; return false;
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
double entityX = livingEntity.getX(); double entityX = livingEntity.getX();
@ -396,20 +396,26 @@ public class PotatoCannonProjectileTypes {
double teleportY = MathHelper.clamp(entityY + (livingEntity.getRNG().nextInt((int) teleportDiameter) - (int) (teleportDiameter / 2)), 0.0D, world.getDimensionHeight() - 1); double teleportY = MathHelper.clamp(entityY + (livingEntity.getRNG().nextInt((int) teleportDiameter) - (int) (teleportDiameter / 2)), 0.0D, world.getDimensionHeight() - 1);
double teleportZ = entityZ + (livingEntity.getRNG().nextDouble() - 0.5D) * teleportDiameter; double teleportZ = entityZ + (livingEntity.getRNG().nextDouble() - 0.5D) * teleportDiameter;
EntityTeleportEvent.ChorusFruit event = ForgeEventFactory.onChorusFruitTeleport(livingEntity, teleportX, teleportY, teleportZ); /* Usable as soon as lowest supported forge > 36.1.3 */
if (event.isCanceled())
return; // EntityTeleportEvent.ChorusFruit event = ForgeEventFactory.onChorusFruitTeleport(livingEntity, teleportX, teleportY, teleportZ);
// if (event.isCanceled())
if (livingEntity.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ(), true)) { // return;
// if (livingEntity.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ(), true)) {
if (livingEntity.attemptTeleport(teleportX, teleportY, teleportZ, true)) {
if (livingEntity.isPassenger()) if (livingEntity.isPassenger())
livingEntity.stopRiding(); livingEntity.stopRiding();
SoundEvent soundevent = livingEntity instanceof FoxEntity ? SoundEvents.ENTITY_FOX_TELEPORT : SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT; SoundEvent soundevent = livingEntity instanceof FoxEntity ? SoundEvents.ENTITY_FOX_TELEPORT : SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT;
world.playSound(null, entityX, entityY, entityZ, soundevent, SoundCategory.PLAYERS, 1.0F, 1.0F); world.playSound(null, entityX, entityY, entityZ, soundevent, SoundCategory.PLAYERS, 1.0F, 1.0F);
livingEntity.playSound(soundevent, 1.0F, 1.0F); livingEntity.playSound(soundevent, 1.0F, 1.0F);
break; livingEntity.setMotion(Vector3d.ZERO);
return true;
} }
} }
return false;
}; };
} }