修复充电站范围显示问题
This commit is contained in:
parent
ba3ad15c0b
commit
db95b322b4
5 changed files with 44 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
||||||
// 1.20.1 2024-12-20T00:15:37.2171993 Block States: superbwarfare
|
// 1.20.1 2025-01-09T21:37:53.6258664 Block States: superbwarfare
|
||||||
f3b778ca36ca78c3d80f1b778078897f59bdb0c5 assets/superbwarfare/blockstates/barbed_wire.json
|
f3b778ca36ca78c3d80f1b778078897f59bdb0c5 assets/superbwarfare/blockstates/barbed_wire.json
|
||||||
0cfad4f53a8047c402edf978d0c8cf6269f063cb assets/superbwarfare/blockstates/cemented_carbide_block.json
|
0cfad4f53a8047c402edf978d0c8cf6269f063cb assets/superbwarfare/blockstates/cemented_carbide_block.json
|
||||||
13e5bd940f02c3719459d17722b79619e98194e5 assets/superbwarfare/blockstates/charging_station.json
|
472c06e6b43ad09925edaa88e9376bfd27ab267f assets/superbwarfare/blockstates/charging_station.json
|
||||||
921500c7cf6c92da0e656486126068bbf5e30348 assets/superbwarfare/blockstates/container.json
|
921500c7cf6c92da0e656486126068bbf5e30348 assets/superbwarfare/blockstates/container.json
|
||||||
62fb0464ca59ac21693639c406e08730427d87b3 assets/superbwarfare/blockstates/deepslate_galena_ore.json
|
62fb0464ca59ac21693639c406e08730427d87b3 assets/superbwarfare/blockstates/deepslate_galena_ore.json
|
||||||
b8b7cdea6c8626c74d652d0b300b3afe19c60674 assets/superbwarfare/blockstates/deepslate_scheelite_ore.json
|
b8b7cdea6c8626c74d652d0b300b3afe19c60674 assets/superbwarfare/blockstates/deepslate_scheelite_ore.json
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
{
|
{
|
||||||
"variants": {
|
"variants": {
|
||||||
"facing=east": {
|
"facing=east,show_range=false": {
|
||||||
"model": "superbwarfare:block/charging_station",
|
"model": "superbwarfare:block/charging_station",
|
||||||
"y": 90
|
"y": 90
|
||||||
},
|
},
|
||||||
"facing=north": {
|
"facing=east,show_range=true": {
|
||||||
|
"model": "superbwarfare:block/charging_station",
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=north,show_range=false": {
|
||||||
"model": "superbwarfare:block/charging_station"
|
"model": "superbwarfare:block/charging_station"
|
||||||
},
|
},
|
||||||
"facing=south": {
|
"facing=north,show_range=true": {
|
||||||
|
"model": "superbwarfare:block/charging_station"
|
||||||
|
},
|
||||||
|
"facing=south,show_range=false": {
|
||||||
"model": "superbwarfare:block/charging_station",
|
"model": "superbwarfare:block/charging_station",
|
||||||
"y": 180
|
"y": 180
|
||||||
},
|
},
|
||||||
"facing=west": {
|
"facing=south,show_range=true": {
|
||||||
|
"model": "superbwarfare:block/charging_station",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=west,show_range=false": {
|
||||||
|
"model": "superbwarfare:block/charging_station",
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,show_range=true": {
|
||||||
"model": "superbwarfare:block/charging_station",
|
"model": "superbwarfare:block/charging_station",
|
||||||
"y": 270
|
"y": 270
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
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.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -26,10 +27,11 @@ import org.jetbrains.annotations.Nullable;
|
||||||
public class ChargingStationBlock extends BaseEntityBlock {
|
public class ChargingStationBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
|
public static final BooleanProperty SHOW_RANGE = BooleanProperty.create("show_range");
|
||||||
|
|
||||||
public ChargingStationBlock() {
|
public ChargingStationBlock() {
|
||||||
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(3.0f).requiresCorrectToolForDrops());
|
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(3.0f).requiresCorrectToolForDrops());
|
||||||
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(SHOW_RANGE, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,10 +73,13 @@ public class ChargingStationBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
|
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
|
||||||
if (pLevel instanceof ServerLevel serverLevel) {
|
if (!pState.is(pNewState.getBlock())) {
|
||||||
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
||||||
if (blockentity instanceof ChargingStationBlockEntity blockEntity) {
|
if (blockentity instanceof ChargingStationBlockEntity blockEntity) {
|
||||||
Containers.dropContents(serverLevel, pPos, blockEntity);
|
if (pLevel instanceof ServerLevel serverLevel) {
|
||||||
|
Containers.dropContents(serverLevel, pPos, blockEntity);
|
||||||
|
}
|
||||||
|
pLevel.updateNeighbourForOutputSignal(pPos, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +88,12 @@ public class ChargingStationBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||||
pBuilder.add(FACING);
|
pBuilder.add(FACING).add(SHOW_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
||||||
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite());
|
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite()).setValue(SHOW_RANGE, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.block.entity;
|
package com.atsuishio.superbwarfare.block.entity;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.block.ChargingStationBlock;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.IChargeEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.IChargeEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
|
@ -58,7 +59,6 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
|
|
||||||
public int fuelTick = 0;
|
public int fuelTick = 0;
|
||||||
public int maxFuelTick = DEFAULT_FUEL_TIME;
|
public int maxFuelTick = DEFAULT_FUEL_TIME;
|
||||||
|
|
||||||
public boolean showRange = false;
|
public boolean showRange = false;
|
||||||
|
|
||||||
protected final ContainerEnergyData dataAccess = new ContainerEnergyData() {
|
protected final ContainerEnergyData dataAccess = new ContainerEnergyData() {
|
||||||
|
@ -105,6 +105,15 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, ChargingStationBlockEntity blockEntity) {
|
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, ChargingStationBlockEntity blockEntity) {
|
||||||
|
if (blockEntity.showRange && !pState.getValue(ChargingStationBlock.SHOW_RANGE)) {
|
||||||
|
pLevel.setBlockAndUpdate(pPos, pState.setValue(ChargingStationBlock.SHOW_RANGE, true));
|
||||||
|
setChanged(pLevel, pPos, pState);
|
||||||
|
}
|
||||||
|
if (!blockEntity.showRange && pState.getValue(ChargingStationBlock.SHOW_RANGE)) {
|
||||||
|
pLevel.setBlockAndUpdate(pPos, pState.setValue(ChargingStationBlock.SHOW_RANGE, false));
|
||||||
|
setChanged(pLevel, pPos, pState);
|
||||||
|
}
|
||||||
|
|
||||||
blockEntity.energyHandler.ifPresent(handler -> {
|
blockEntity.energyHandler.ifPresent(handler -> {
|
||||||
int energy = handler.getEnergyStored();
|
int energy = handler.getEnergyStored();
|
||||||
if (energy > 0) {
|
if (energy > 0) {
|
||||||
|
@ -329,6 +338,7 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
public CompoundTag getUpdateTag() {
|
public CompoundTag getUpdateTag() {
|
||||||
CompoundTag compoundtag = new CompoundTag();
|
CompoundTag compoundtag = new CompoundTag();
|
||||||
ContainerHelper.saveAllItems(compoundtag, this.items, true);
|
ContainerHelper.saveAllItems(compoundtag, this.items, true);
|
||||||
|
compoundtag.putBoolean("ShowRange", this.showRange);
|
||||||
return compoundtag;
|
return compoundtag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.client.renderer.block;
|
package com.atsuishio.superbwarfare.client.renderer.block;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.block.ChargingStationBlock;
|
||||||
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
||||||
import com.atsuishio.superbwarfare.client.renderer.CustomRenderType;
|
import com.atsuishio.superbwarfare.client.renderer.CustomRenderType;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
@ -15,8 +16,7 @@ public class ChargingStationBlockEntityRenderer implements BlockEntityRenderer<C
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(ChargingStationBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) {
|
public void render(ChargingStationBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) {
|
||||||
// TODO 正确判断是否开启范围展示
|
if (!pBlockEntity.getBlockState().getValue(ChargingStationBlock.SHOW_RANGE)) return;
|
||||||
if (!pBlockEntity.showRange) return;
|
|
||||||
|
|
||||||
pPoseStack.pushPose();
|
pPoseStack.pushPose();
|
||||||
var pos = pBlockEntity.getBlockPos();
|
var pos = pBlockEntity.getBlockPos();
|
||||||
|
|
Loading…
Add table
Reference in a new issue