mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Campfire movement behaviour
- Campfire now spawns smoke when moved
This commit is contained in:
parent
111e69d189
commit
2675d6ae2f
2 changed files with 50 additions and 5 deletions
|
@ -1,22 +1,29 @@
|
|||
package com.simibubi.create;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour;
|
||||
import com.simibubi.create.content.contraptions.components.actors.CampfireMovementBehaviour;
|
||||
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;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class AllMovementBehaviours {
|
||||
private static final HashMap<ResourceLocation, MovementBehaviour> movementBehaviours = new HashMap<>();
|
||||
|
||||
public static void addMovementBehaviour(ResourceLocation resourceLocation, MovementBehaviour movementBehaviour) {
|
||||
private static void addMovementBehaviour(ResourceLocation resourceLocation, MovementBehaviour movementBehaviour) {
|
||||
movementBehaviours.put(resourceLocation, movementBehaviour);
|
||||
}
|
||||
|
||||
public static void addMovementBehaviour(Block block, MovementBehaviour movementBehaviour) {
|
||||
addMovementBehaviour(block.getRegistryName(), movementBehaviour);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MovementBehaviour getMovementBehaviour(ResourceLocation resourceLocation) {
|
||||
return movementBehaviours.getOrDefault(resourceLocation, null);
|
||||
|
@ -37,6 +44,7 @@ public class AllMovementBehaviours {
|
|||
}
|
||||
|
||||
static void register() {
|
||||
addMovementBehaviour(Blocks.BELL.getRegistryName(), new BellMovementBehaviour());
|
||||
addMovementBehaviour(Blocks.BELL, new BellMovementBehaviour());
|
||||
addMovementBehaviour(Blocks.CAMPFIRE, new CampfireMovementBehaviour());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.simibubi.create.content.contraptions.components.actors;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
|
||||
import net.minecraft.block.CampfireBlock;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
|
||||
public class CampfireMovementBehaviour extends MovementBehaviour {
|
||||
@Override
|
||||
public boolean hasSpecialMovementRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MovementContext context) {
|
||||
if (context.world == null || !context.world.isRemote || context.position == null
|
||||
|| !context.state.get(CampfireBlock.LIT))
|
||||
return;
|
||||
|
||||
// Mostly copied from CampfireBlock and CampfireTileEntity
|
||||
Random random = context.world.rand;
|
||||
if (random.nextFloat() < 0.11F) {
|
||||
for (int i = 0; i < random.nextInt(2) + 2; ++i) {
|
||||
context.world.addOptionalParticle(
|
||||
context.state.get(CampfireBlock.SIGNAL_FIRE) ? ParticleTypes.CAMPFIRE_SIGNAL_SMOKE
|
||||
: ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
true, context.position.getX() + random.nextDouble() / (random.nextBoolean() ? 3D : -3D),
|
||||
context.position.getY() + random.nextDouble() + random.nextDouble(),
|
||||
context.position.getZ() + random.nextDouble() / (random.nextBoolean() ? 3D : -3D), 0.0D, 0.07D,
|
||||
0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue