Skip to content

Commit

Permalink
Switched Up!
Browse files Browse the repository at this point in the history
- Replace switches with new model & texture
- Rename TileEntity -> BlockEntity
  • Loading branch information
IThundxr committed Nov 19, 2023
1 parent ae7830e commit 0d6499b
Show file tree
Hide file tree
Showing 20 changed files with 289 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class SwitchDisplaySource extends SingleLineDisplaySource {
@Override
protected MutableComponent provideLine(DisplayLinkContext context, DisplayTargetStats stats) {
if (context.getSourceBlockEntity() instanceof TrackSwitchTileEntity sw) {
if (context.getSourceBlockEntity() instanceof TrackSwitchBlockEntity sw) {
return Components.translatable("railways.display_source.switch."+sw.getState().getSerializedName());
}
return Components.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public boolean canCoexistWith(EdgePointType<?> otherType, boolean front) {
public void blockEntityAdded(BlockEntity tile, boolean front) {
super.blockEntityAdded(tile, front);

if (tile instanceof TrackSwitchTileEntity te) {
if (tile instanceof TrackSwitchBlockEntity te) {
te.calculateExits(this);
automatic = te.isAutomatic();
locked = te.isLocked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class TrackSwitchBlock extends HorizontalDirectionalBlock implements IBE<TrackSwitchTileEntity>, IWrenchable {
public abstract class TrackSwitchBlock extends HorizontalDirectionalBlock implements IBE<TrackSwitchBlockEntity>, IWrenchable {
boolean isAutomatic;
// public static final Property<SwitchState> STATE = EnumProperty.create("state", SwitchState.class);
public static final BooleanProperty LOCKED = BlockStateProperties.LOCKED;
Expand Down Expand Up @@ -183,12 +183,12 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
}

@Override
public Class<TrackSwitchTileEntity> getBlockEntityClass() {
return TrackSwitchTileEntity.class;
public Class<TrackSwitchBlockEntity> getBlockEntityClass() {
return TrackSwitchBlockEntity.class;
}

@Override
public BlockEntityType<? extends TrackSwitchTileEntity> getBlockEntityType() {
public BlockEntityType<? extends TrackSwitchBlockEntity> getBlockEntityType() {
return isAutomatic ?
CRBlockEntities.BRASS_SWITCH.get() :
CRBlockEntities.ANDESITE_SWITCH.get();
Expand Down Expand Up @@ -234,7 +234,7 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new
return InteractionResult.SUCCESS;
}

TrackSwitchTileEntity te = getBlockEntity(level, pos);
TrackSwitchBlockEntity te = getBlockEntity(level, pos);
if (te != null) {
if (player.getGameProfile() == ConductorEntity.FAKE_PLAYER_PROFILE) {
return te.onProjectileHit() ? InteractionResult.CONSUME : InteractionResult.SUCCESS;
Expand All @@ -250,7 +250,7 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new
public void onProjectileHit(Level level, BlockState state, BlockHitResult hit, Projectile projectile) {
super.onProjectileHit(level, state, hit, projectile);

TrackSwitchTileEntity te = getBlockEntity(level, hit.getBlockPos());
TrackSwitchBlockEntity te = getBlockEntity(level, hit.getBlockPos());
if (te != null) {
te.onProjectileHit();
}
Expand All @@ -263,7 +263,7 @@ public void onProjectileHit(Level level, BlockState state, BlockHitResult hit, P
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
super.neighborChanged(state, level, pos, block, fromPos, isMoving);

TrackSwitchTileEntity te = getBlockEntity(level, pos);
TrackSwitchBlockEntity te = getBlockEntity(level, pos);
if (te != null) {
te.checkRedstoneInputs();
}
Expand All @@ -286,7 +286,7 @@ public boolean hasAnalogOutputSignal(@NotNull BlockState state) {
*/
@Override
public int getAnalogOutputSignal(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos) {
if (level.getBlockEntity(pos) instanceof TrackSwitchTileEntity te)
if (level.getBlockEntity(pos) instanceof TrackSwitchBlockEntity te)
return te.getTargetAnalogOutput();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;


public class TrackSwitchTileEntity extends SmartBlockEntity implements ITransformableBlockEntity, IHaveGoggleInformation {
public class TrackSwitchBlockEntity extends SmartBlockEntity implements ITransformableBlockEntity, IHaveGoggleInformation {
public TrackTargetingBehaviour<TrackSwitch> edgePoint;
private SwitchState state;
private int lastAnalogOutput = 0;
Expand Down Expand Up @@ -111,7 +111,7 @@ public TrackSwitch getSwitch() {

final LerpedFloat lerpedAngle = LerpedFloat.angular().chase(0.0, 0.3, LerpedFloat.Chaser.EXP);

public TrackSwitchTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
public TrackSwitchBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.railwayteam.railways.content.switches.TrackSwitchBlock.SwitchState;
import com.railwayteam.railways.content.switches.TrackSwitchTileEntity.PonderData;
import com.railwayteam.railways.content.switches.TrackSwitchBlockEntity.PonderData;
import com.railwayteam.railways.registry.CRBlockPartials;
import com.railwayteam.railways.util.CustomTrackOverlayRendering;
import com.simibubi.create.content.trains.track.ITrackBlock;
Expand All @@ -26,13 +26,13 @@

import java.util.Map;

public class TrackSwitchRenderer extends SmartBlockEntityRenderer<TrackSwitchTileEntity> {
public class TrackSwitchRenderer extends SmartBlockEntityRenderer<TrackSwitchBlockEntity> {
public TrackSwitchRenderer(Context ctx) {
super(ctx);
}

@Override
protected void renderSafe(TrackSwitchTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
protected void renderSafe(TrackSwitchBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
renderFlagState(te, partialTicks, ms, buffer, light);
renderTrackOverlay(te, ms, buffer, light, overlay, te.edgePoint);
Expand Down Expand Up @@ -60,7 +60,7 @@ private void renderPonderData(PonderWorld ponderWorld, SwitchState state, Ponder
ms.popPose();
}

private void renderFlagState(TrackSwitchTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
private void renderFlagState(TrackSwitchBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light) {
BlockState state = te.getBlockState();
ms.pushPose();
Expand All @@ -84,11 +84,9 @@ private void renderFlagState(TrackSwitchTileEntity te, float partialTicks, PoseS

// Rotate just enough to touch the front or back edge
if (te.isReverseLeft() || (te.isNormal() && te.exitCount == 2 && te.hasExit(SwitchState.REVERSE_RIGHT))) {
// buf = buf.rotate(Direction.NORTH, -1.1f);
te.lerpedAngle.updateChaseTarget(-1.1f);
te.lerpedAngle.updateChaseTarget(-0.40f);
} else if (te.isReverseRight() || (te.isNormal() && te.exitCount == 2 && te.hasExit(SwitchState.REVERSE_LEFT))) {
// buf = buf.rotate(Direction.NORTH, 1.1f);
te.lerpedAngle.updateChaseTarget(1.1f);
te.lerpedAngle.updateChaseTarget(0.40f);
} else {
te.lerpedAngle.updateChaseTarget(0.0f);
}
Expand Down Expand Up @@ -124,7 +122,7 @@ private void renderFlagState(TrackSwitchTileEntity te, float partialTicks, PoseS
ms.popPose();
}

private void renderTrackOverlay(TrackSwitchTileEntity te, PoseStack ms, MultiBufferSource buffer,
private void renderTrackOverlay(TrackSwitchBlockEntity te, PoseStack ms, MultiBufferSource buffer,
int light, int overlay, TrackTargetingBehaviour<TrackSwitch> target) {
BlockPos pos = te.getBlockPos();
boolean offsetToSide = CustomTrackOverlayRendering.overlayWillOverlap(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ private void placeCorrectedBlock(BlockState state, Level level, BlockPos pos, Pl
level.setBlock(pos, targetState, 3);

BlockEntity newBlockEntity = level.getBlockEntity(pos);
if (!(newBlockEntity instanceof AbstractBogeyBlockEntity newTileEntity)) {
if (!(newBlockEntity instanceof AbstractBogeyBlockEntity newBlockEntity)) {
cir.setReturnValue(InteractionResult.FAIL);
return;
}
newTileEntity.setBogeyData(oldData);
newBlockEntity.setBogeyData(oldData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = StandardBogeyBlockEntity.class, remap = false)
public class MixinStandardBogeyTileEntity implements IStandardBogeyTEVirtualCoupling {
public class MixinStandardBogeyBlockEntity implements IStandardBogeyTEVirtualCoupling {
private double coupling = -1;
@Override
public void setCouplingDistance(double distance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = BogeyBlockEntityRenderer.class, remap = false)
public class MixinBogeyTileEntityRenderer {
public class MixinBogeyBlockEntityRenderer {
@Inject(method = "renderSafe", at = @At("RETURN"), remap = false)
private <T extends BlockEntity> void railways$renderVirtualCoupling(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay, CallbackInfo ci) {
if (te instanceof StandardBogeyBlockEntity sbte && te instanceof IStandardBogeyTEVirtualCoupling virtualCoupling) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.railwayteam.railways.content.coupling.coupler.TrackCouplerBlockEntity;
import com.railwayteam.railways.content.switches.TrackSwitchBlock.SwitchConstraint;
import com.railwayteam.railways.content.switches.TrackSwitchBlock.SwitchState;
import com.railwayteam.railways.content.switches.TrackSwitchTileEntity;
import com.railwayteam.railways.content.switches.TrackSwitchTileEntity.PonderData;
import com.railwayteam.railways.content.switches.TrackSwitchBlockEntity;
import com.railwayteam.railways.content.switches.TrackSwitchBlockEntity.PonderData;
import com.railwayteam.railways.mixin_interfaces.IStandardBogeyTEVirtualCoupling;
import com.railwayteam.railways.registry.CRBlocks;
import com.simibubi.create.AllBlockEntityTypes;
Expand Down Expand Up @@ -542,7 +542,7 @@ public static void trackSwitch(SceneBuilder scene, SceneBuildingUtil util) {
@Override
protected void onHitBlock(@NotNull BlockHitResult result) {
super.onHitBlock(result);
if (level.getBlockEntity(result.getBlockPos()) instanceof TrackSwitchTileEntity switchBE) {
if (level.getBlockEntity(result.getBlockPos()) instanceof TrackSwitchBlockEntity switchBE) {
switchBE.setStatePonder(switchBE.getState().nextStateForPonder(SwitchConstraint.NONE));

int output = switchBE.getTargetAnalogOutput();
Expand Down Expand Up @@ -586,8 +586,8 @@ public boolean isComplete() {
return true;
}

private Optional<TrackSwitchTileEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchTileEntity switchBE)
private Optional<TrackSwitchBlockEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchBlockEntity switchBE)
return Optional.of(switchBE);
return Optional.empty();
}
Expand All @@ -612,8 +612,8 @@ public boolean isComplete() {
return true;
}

private Optional<TrackSwitchTileEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchTileEntity switchBE)
private Optional<TrackSwitchBlockEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchBlockEntity switchBE)
return Optional.of(switchBE);
return Optional.empty();
}
Expand All @@ -638,8 +638,8 @@ public boolean isComplete() {
return true;
}

private Optional<TrackSwitchTileEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchTileEntity switchBE)
private Optional<TrackSwitchBlockEntity> getSwitch(PonderScene scene) {
if (scene.getWorld().getBlockEntity(switchPos) instanceof TrackSwitchBlockEntity switchBE)
return Optional.of(switchBE);
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.railwayteam.railways.content.smokestack.DieselSmokeStackBlockEntity;
import com.railwayteam.railways.content.smokestack.DieselSmokeStackRenderer;
import com.railwayteam.railways.content.switches.TrackSwitchRenderer;
import com.railwayteam.railways.content.switches.TrackSwitchTileEntity;
import com.railwayteam.railways.content.switches.TrackSwitchBlockEntity;
import com.simibubi.create.content.trains.bogey.BogeyBlockEntityRenderer;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.entry.BlockEntityEntry;
Expand All @@ -34,12 +34,12 @@ public class CRBlockEntities {
.renderer(() -> TrackCouplerRenderer::new)
.register();

public static final BlockEntityEntry<TrackSwitchTileEntity> ANDESITE_SWITCH = REGISTRATE.blockEntity("track_switch_andesite", TrackSwitchTileEntity::new)
public static final BlockEntityEntry<TrackSwitchBlockEntity> ANDESITE_SWITCH = REGISTRATE.blockEntity("track_switch_andesite", TrackSwitchBlockEntity::new)
.validBlocks(CRBlocks.ANDESITE_SWITCH)
.renderer(() -> TrackSwitchRenderer::new)
.register();

public static final BlockEntityEntry<TrackSwitchTileEntity> BRASS_SWITCH = REGISTRATE.blockEntity("track_switch_brass", TrackSwitchTileEntity::new)
public static final BlockEntityEntry<TrackSwitchBlockEntity> BRASS_SWITCH = REGISTRATE.blockEntity("track_switch_brass", TrackSwitchBlockEntity::new)
.validBlocks(CRBlocks.BRASS_SWITCH)
.renderer(() -> TrackSwitchRenderer::new)
.register();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"credit": "Made with Blockbench",
"parent": "railways:block/track_switch_andesite/block",
"parent": "andesite-track-switch",
"textures": {
"0": "railways:block/track_switch/axis",
"1": "railways:block/track_switch/axis_top",
Expand All @@ -9,8 +9,8 @@
"elements": [
{
"name": "grip",
"from": [7, 8.5, 12],
"to": [9, 18.5, 13],
"from": [7.01, 8.5, 12],
"to": [8.99, 18.5, 13],
"rotation": {"angle": -22.5, "axis": "x", "origin": [8, 16, 14]},
"faces": {
"north": {"uv": [7, 0, 9, 10], "texture": "#0"},
Expand Down Expand Up @@ -44,4 +44,4 @@
"children": [0, 1]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"to": [7, 26, 12],
"rotation": {"angle": 0, "axis": "y", "origin": [0, -4, 0]},
"faces": {
"north": {"uv": [0, 0, 1, 16], "texture": "#5"},
"east": {"uv": [0, 0, 16, 16], "rotation": 90, "texture": "#5"},
"south": {"uv": [15, 0, 16, 16], "texture": "#5"},
"west": {"uv": [0, 0, 16, 16], "texture": "#5"},
"up": {"uv": [0, 0, 16, 1], "rotation": 90, "texture": "#5"},
"down": {"uv": [0, 15, 16, 16], "rotation": 90, "texture": "#5"}
"north": {"uv": [0, 0, 1, 8], "texture": "#5"},
"east": {"uv": [0, 0, 8, 8], "rotation": 90, "texture": "#5"},
"south": {"uv": [7, 0, 8, 8], "texture": "#5"},
"west": {"uv": [0, 0, 8, 8], "texture": "#5"},
"up": {"uv": [0, 0, 8, 1], "rotation": 90, "texture": "#5"},
"down": {"uv": [0, 7, 8, 8], "rotation": 90, "texture": "#5"}
}
},
{
Expand Down Expand Up @@ -208,21 +208,18 @@
"name": "flag",
"origin": [0, 0, 0],
"color": 0,
"nbt": "{}",
"children": [0, 1, 2]
},
{
"name": "handle",
"origin": [8, 8, 8],
"color": 0,
"nbt": "{}",
"children": [3, 4]
},
{
"name": "base",
"origin": [8, 8, 8],
"color": 0,
"nbt": "{}",
"children": [5, 6, 7, 8, 9, 10]
}
]
Expand Down
Loading

0 comments on commit 0d6499b

Please sign in to comment.