mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Changeling disguised as anvils will now do that anvil thing when they fall
This commit is contained in:
parent
d29cc60d01
commit
0ddd43c39a
6 changed files with 62 additions and 8 deletions
|
@ -160,6 +160,10 @@ public class Disguise implements NbtSerialisable {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onImpact(Pony pony, float distance, float damageMultiplier) {
|
||||||
|
EntityBehaviour.forEntity(entity).onImpact(pony, entity, distance, damageMultiplier);
|
||||||
|
}
|
||||||
|
|
||||||
private void onEntityLoaded(Caster<?> source) {
|
private void onEntityLoaded(Caster<?> source) {
|
||||||
source.getEntity().calculateDimensions();
|
source.getEntity().calculateDimensions();
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ public class EntityBehaviour<T extends Entity> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onImpact(Caster<?> source, T entity, float distance, float damageMultiplier) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public T onCreate(T entity, Disguise context, boolean wasNew) {
|
public T onCreate(T entity, Disguise context, boolean wasNew) {
|
||||||
entity.extinguish();
|
entity.extinguish();
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -7,12 +7,13 @@ import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.mixin.MixinBlockEntity;
|
import com.minelittlepony.unicopia.mixin.MixinBlockEntity;
|
||||||
|
import com.minelittlepony.unicopia.mixin.MixinFallingBlock;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.DoorBlock;
|
import net.minecraft.block.DoorBlock;
|
||||||
|
import net.minecraft.block.FallingBlock;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.entity.ChestBlockEntity;
|
import net.minecraft.block.entity.ChestBlockEntity;
|
||||||
import net.minecraft.block.entity.EnderChestBlockEntity;
|
import net.minecraft.block.entity.EnderChestBlockEntity;
|
||||||
|
@ -37,23 +38,42 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
|
||||||
return FULL_BLOCK;
|
return FULL_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onImpact(Caster<?> source, FallingBlockEntity entity, float distance, float damageMultiplier) {
|
||||||
|
if (source.getEntity().fallDistance > 3) {
|
||||||
|
entity.fallDistance = source.getEntity().fallDistance;
|
||||||
|
entity.handleFallDamage(distance, damageMultiplier);
|
||||||
|
|
||||||
|
BlockState state = entity.getBlockState();
|
||||||
|
if (state.getBlock() instanceof FallingBlock) {
|
||||||
|
((FallingBlock)state.getBlock()).onLanding(entity.world, entity.getBlockPos(), state, state, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FallingBlockEntity configure(FallingBlockEntity entity, Block block) {
|
||||||
|
if (block instanceof MixinFallingBlock) {
|
||||||
|
((MixinFallingBlock)block).invokeConfigureFallingBlockEntity(entity);
|
||||||
|
}
|
||||||
|
entity.dropItem = false;
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FallingBlockEntity onCreate(FallingBlockEntity entity, Disguise context, boolean replaceOld) {
|
public FallingBlockEntity onCreate(FallingBlockEntity entity, Disguise context, boolean replaceOld) {
|
||||||
super.onCreate(entity, context, replaceOld);
|
super.onCreate(entity, context, replaceOld);
|
||||||
|
|
||||||
BlockState state = entity.getBlockState();
|
BlockState state = entity.getBlockState();
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.SAND) {
|
|
||||||
block = Blocks.BLACKSTONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.isIn(BlockTags.DOORS) && block instanceof DoorBlock) {
|
if (state.isIn(BlockTags.DOORS) && block instanceof DoorBlock) {
|
||||||
BlockState lowerState = state.with(DoorBlock.HALF, DoubleBlockHalf.LOWER);
|
BlockState lowerState = state.with(DoorBlock.HALF, DoubleBlockHalf.LOWER);
|
||||||
BlockState upperState = state.with(DoorBlock.HALF, DoubleBlockHalf.UPPER);
|
BlockState upperState = state.with(DoorBlock.HALF, DoubleBlockHalf.UPPER);
|
||||||
|
|
||||||
context.attachExtraEntity(new FallingBlockEntity(entity.world, entity.getX(), entity.getY(), entity.getZ(), upperState));
|
context.attachExtraEntity(configure(new FallingBlockEntity(entity.world, entity.getX(), entity.getY(), entity.getZ(), upperState), block));
|
||||||
|
|
||||||
return new FallingBlockEntity(entity.world, entity.getX(), entity.getY() + 1, entity.getZ(), lowerState);
|
return configure(new FallingBlockEntity(entity.world, entity.getX(), entity.getY() + 1, entity.getZ(), lowerState), block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block instanceof BlockEntityProvider) {
|
if (block instanceof BlockEntityProvider) {
|
||||||
|
@ -62,7 +82,7 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
|
||||||
context.addBlockEntity(b);
|
context.addBlockEntity(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return configure(entity, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.minelittlepony.unicopia.ability.AbilityDispatcher;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Attached;
|
import com.minelittlepony.unicopia.ability.magic.Attached;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Spell;
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.ShieldSpell;
|
import com.minelittlepony.unicopia.ability.magic.spell.ShieldSpell;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.SpellRegistry;
|
import com.minelittlepony.unicopia.ability.magic.spell.SpellRegistry;
|
||||||
import com.minelittlepony.unicopia.entity.Physics;
|
import com.minelittlepony.unicopia.entity.Physics;
|
||||||
|
@ -339,10 +340,21 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
}
|
}
|
||||||
|
|
||||||
distance *= g;
|
distance *= g;
|
||||||
|
distance = Math.max(0, distance - 5);
|
||||||
|
|
||||||
return Optional.of(Math.max(0, distance - 5));
|
float d = distance;
|
||||||
|
getSpellOrEmpty(DisguiseSpell.class, false).ifPresent(spell -> {
|
||||||
|
spell.getDisguise().onImpact(this, d, damageMultiplier);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Optional.of(distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float d = distance;
|
||||||
|
getSpellOrEmpty(DisguiseSpell.class, false).ifPresent(spell -> {
|
||||||
|
spell.getDisguise().onImpact(this, d, damageMultiplier);
|
||||||
|
});
|
||||||
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.minelittlepony.unicopia.mixin;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
import net.minecraft.block.FallingBlock;
|
||||||
|
import net.minecraft.entity.FallingBlockEntity;
|
||||||
|
|
||||||
|
@Mixin(FallingBlock.class)
|
||||||
|
public interface MixinFallingBlock {
|
||||||
|
@Invoker
|
||||||
|
void invokeConfigureFallingBlockEntity(FallingBlockEntity entity);
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinBlockEntity",
|
"MixinBlockEntity",
|
||||||
"MixinBlockItem",
|
"MixinBlockItem",
|
||||||
|
"MixinFallingBlock",
|
||||||
"MixinItem",
|
"MixinItem",
|
||||||
"MixinItemEntity",
|
"MixinItemEntity",
|
||||||
"MixinItems",
|
"MixinItems",
|
||||||
|
|
Loading…
Reference in a new issue