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;
import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
@ -34,5 +36,7 @@ public class AllMovementBehaviours {
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
renderOrder.add(0, info.pos);
CompoundNBT tag = info.nbt;
if (tag == null || AllMovementBehaviours.hasMovementBehaviour(block))
MovementBehaviour movementBehaviour = AllMovementBehaviours.getMovementBehaviour(block);
if (tag == null || movementBehaviour == null || movementBehaviour.hasSpecialMovementRenderer())
return;
tag.putInt("x", info.pos.getX());
@ -472,6 +473,8 @@ public abstract class Contraption {
tag.putInt("z", info.pos.getZ());
TileEntity te = TileEntity.create(tag);
if (te == null)
return;
te.setLocation(new WrappedWorld(world) {
@Override

View file

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

View file

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

View file

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