Skip to content

Commit

Permalink
fix: Fix warp plates showing dust instead of warp particles until the…
Browse files Browse the repository at this point in the history
…ir gui was opened once
  • Loading branch information
BlayTheNinth committed Dec 14, 2023
1 parent 903979b commit 3829584
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -30,29 +31,46 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Random;
import java.util.Locale;

public class WarpPlateBlock extends WaystoneBlockBase {

public enum WarpPlateStatus implements StringRepresentable {
IDLE,
ACTIVE,
INVALID;

@Override
public String getSerializedName() {
return name().toLowerCase(Locale.ROOT);
}
}

private static final Style GALACTIC_STYLE = Style.EMPTY.withFont(new ResourceLocation("minecraft", "alt"));

private static final VoxelShape SHAPE = Shapes.or(
box(0.0, 0.0, 0.0, 16.0, 1.0, 16.0),
box(3.0, 1.0, 3.0, 13.0, 2.0, 13.0)
).optimize();

@Deprecated
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
public static final EnumProperty<WarpPlateStatus> STATUS = EnumProperty.create("status", WarpPlateStatus.class);

public WarpPlateBlock(Properties properties) {
super(properties);
registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false).setValue(ACTIVE, false));
registerDefaultState(this.stateDefinition.any()
.setValue(WATERLOGGED, false)
.setValue(ACTIVE, false)
.setValue(STATUS, WarpPlateStatus.IDLE));
}

@Override
Expand Down Expand Up @@ -95,6 +113,7 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(ACTIVE);
builder.add(STATUS);
}

@Override
Expand All @@ -112,20 +131,26 @@ public void entityInside(BlockState blockState, Level world, BlockPos pos, Entit

@Override
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource random) {
if (state.getValue(ACTIVE)) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof WarpPlateBlockEntity) {
IWaystone targetWaystone = ((WarpPlateBlockEntity) blockEntity).getTargetWaystone();
if (targetWaystone != null && targetWaystone.isValid()) {
for (int i = 0; i < 50; i++) {
world.addParticle(ParticleTypes.CRIMSON_SPORE, pos.getX() + Math.random(), pos.getY() + Math.random() * 2, pos.getZ() + Math.random(), 0f, 0f, 0f);
world.addParticle(ParticleTypes.PORTAL, pos.getX() + Math.random(), pos.getY() + Math.random() * 2, pos.getZ() + Math.random(), 0f, 0f, 0f);
}
} else {
for (int i = 0; i < 10; i++) {
world.addParticle(ParticleTypes.SMOKE, pos.getX() + Math.random(), pos.getY(), pos.getZ() + Math.random(), 0f, 0.01f, 0f);
}
}
if (state.getValue(STATUS) == WarpPlateStatus.ACTIVE) {
for (int i = 0; i < 50; i++) {
world.addParticle(ParticleTypes.CRIMSON_SPORE,
pos.getX() + Math.random(),
pos.getY() + Math.random() * 2,
pos.getZ() + Math.random(),
0f,
0f,
0f);
world.addParticle(ParticleTypes.PORTAL,
pos.getX() + Math.random(),
pos.getY() + Math.random() * 2,
pos.getZ() + Math.random(),
0f,
0f,
0f);
}
} else if (state.getValue(STATUS) == WarpPlateStatus.INVALID) {
for (int i = 0; i < 10; i++) {
world.addParticle(ParticleTypes.SMOKE, pos.getX() + Math.random(), pos.getY(), pos.getZ() + Math.random(), 0f, 0.01f, 0f);
}
}
}
Expand Down Expand Up @@ -175,6 +200,8 @@ public static Component getGalacticName(IWaystone waystone) {
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
return world.isClientSide ? null : createTickerHelper(type, ModBlockEntities.warpPlate.get(), (level, pos, state2, blockEntity) -> blockEntity.serverTick());
return world.isClientSide ? null : createTickerHelper(type,
ModBlockEntities.warpPlate.get(),
(level, pos, state2, blockEntity) -> blockEntity.serverTick());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ public MenuProvider getSettingsMenuProvider() {
public void onEntityCollision(Entity entity) {
Integer ticksPassed = ticksPassedPerEntity.putIfAbsent(entity, 0);
if (ticksPassed == null || ticksPassed != -1) {
level.setBlock(worldPosition, getBlockState().setValue(WarpPlateBlock.ACTIVE, true), 3);
final var status = getTargetWaystone().isValid() ? WarpPlateBlock.WarpPlateStatus.ACTIVE : WarpPlateBlock.WarpPlateStatus.INVALID;
level.setBlock(worldPosition, getBlockState()
.setValue(WarpPlateBlock.ACTIVE, true)
.setValue(WarpPlateBlock.STATUS, status), 3);
}
}

Expand Down Expand Up @@ -249,7 +252,7 @@ public void serverTick() {
attunementTicks = 0;
}

if (getBlockState().getValue(WarpPlateBlock.ACTIVE)) {
if (getBlockState().getValue(WarpPlateBlock.STATUS) != WarpPlateBlock.WarpPlateStatus.IDLE) {
AABB boundsAbove = new AABB(worldPosition.getX(),
worldPosition.getY(),
worldPosition.getZ(),
Expand All @@ -258,7 +261,9 @@ public void serverTick() {
worldPosition.getZ() + 1);
List<Entity> entities = level.getEntities((Entity) null, boundsAbove, EntitySelector.ENTITY_STILL_ALIVE);
if (entities.isEmpty()) {
level.setBlock(worldPosition, getBlockState().setValue(WarpPlateBlock.ACTIVE, false), 3);
level.setBlock(worldPosition, getBlockState()
.setValue(WarpPlateBlock.ACTIVE, false)
.setValue(WarpPlateBlock.STATUS, WarpPlateBlock.WarpPlateStatus.IDLE), 3);
ticksPassedPerEntity.clear();
}
}
Expand Down

0 comments on commit 3829584

Please sign in to comment.