bell movement behaviour

This commit is contained in:
LordGrimmauld 2020-08-09 12:40:33 +02:00
parent 9bf81f4d7f
commit 111e69d189
6 changed files with 60 additions and 10 deletions

View File

@ -1,8 +1,10 @@
package com.simibubi.create; package com.simibubi.create;
import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullConsumer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -34,5 +36,7 @@ public class AllMovementBehaviours {
return b -> addMovementBehaviour(b.getRegistryName(), movementBehaviour); return b -> addMovementBehaviour(b.getRegistryName(), movementBehaviour);
} }
static void register() {} static void register() {
addMovementBehaviour(Blocks.BELL.getRegistryName(), new BellMovementBehaviour());
}
} }

View File

@ -0,0 +1,32 @@
package com.simibubi.create.content.contraptions.components.actors;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public class BellMovementBehaviour extends MovementBehaviour {
@Override
public boolean hasSpecialMovementRenderer() {
return false;
}
@Override
public void onSpeedChanged(MovementContext context, Vec3d oldMotion, Vec3d motion) {
double dotProduct = oldMotion.dotProduct(motion);
if (dotProduct <= 0 && (context.relativeMotion.length() != 0 || context.rotation.length() == 0)
|| context.firstMovement)
context.world.playSound(null, new BlockPos(context.position), SoundEvents.BLOCK_BELL_USE,
SoundCategory.BLOCKS, 2.0F, 1.0F);
}
@Override
public void stopMoving(MovementContext context) {
context.world.playSound(null, new BlockPos(context.position), SoundEvents.BLOCK_BELL_USE, SoundCategory.BLOCKS,
2.0F, 1.0F);
}
}

View File

@ -464,7 +464,8 @@ public abstract class Contraption {
else else
renderOrder.add(0, info.pos); renderOrder.add(0, info.pos);
CompoundNBT tag = info.nbt; CompoundNBT tag = info.nbt;
if (tag == null || AllMovementBehaviours.hasMovementBehaviour(block)) MovementBehaviour movementBehaviour = AllMovementBehaviours.getMovementBehaviour(block);
if (tag == null || movementBehaviour == null || movementBehaviour.hasSpecialMovementRenderer())
return; return;
tag.putInt("x", info.pos.getX()); tag.putInt("x", info.pos.getX());
@ -472,6 +473,8 @@ public abstract class Contraption {
tag.putInt("z", info.pos.getZ()); tag.putInt("z", info.pos.getZ());
TileEntity te = TileEntity.create(tag); TileEntity te = TileEntity.create(tag);
if (te == null)
return;
te.setLocation(new WrappedWorld(world) { te.setLocation(new WrappedWorld(world) {
@Override @Override

View File

@ -459,6 +459,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
boolean newPosVisited = false; boolean newPosVisited = false;
BlockPos gridPosition = new BlockPos(actorPosition); BlockPos gridPosition = new BlockPos(actorPosition);
Vec3d oldMotion = context.motion;
if (!context.stall) { if (!context.stall) {
Vec3d previousPosition = context.position; Vec3d previousPosition = context.position;
@ -500,6 +501,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
actor.visitNewPosition(context, gridPosition); actor.visitNewPosition(context, gridPosition);
context.firstMovement = false; context.firstMovement = false;
} }
if (!oldMotion.equals(context.motion))
actor.onSpeedChanged(context, oldMotion, context.motion);
actor.tick(context); actor.tick(context);
contraption.stalled |= context.stall; contraption.stalled |= context.stall;
} }

View File

@ -109,8 +109,9 @@ public class ContraptionRenderer {
.translate(blockInfo.pos); .translate(blockInfo.pos);
} }
Contraption.getMovement(blockInfo.state) MovementBehaviour movementBehaviour = Contraption.getMovement(blockInfo.state);
.renderInContraption(context, ms, msLocal, buffer); if (movementBehaviour != null)
movementBehaviour.renderInContraption(context, ms, msLocal, buffer);
for (MatrixStack m : matrixStacks) for (MatrixStack m : matrixStacks)
m.pop(); m.pop();

View File

@ -47,8 +47,15 @@ public abstract class MovementBehaviour {
} }
public boolean hasSpecialMovementRenderer() {
return true;
}
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
IRenderTypeBuffer buffer) {} IRenderTypeBuffer buffer) {}
public void onSpeedChanged(MovementContext context, Vec3d oldMotion, Vec3d motion) {
}
} }