添加雷达模型旋转,调整server tick方法
This commit is contained in:
parent
594707ae77
commit
314cc0e6e2
3 changed files with 28 additions and 18 deletions
|
@ -35,6 +35,8 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider {
|
||||||
public static final int DEFAULT_ENERGY_COST = 256;
|
public static final int DEFAULT_ENERGY_COST = 256;
|
||||||
public static final int MAX_ENERGY_COST = 1024;
|
public static final int MAX_ENERGY_COST = 1024;
|
||||||
|
|
||||||
|
public static final int DEFAULT_MIN_ENERGY = 64000;
|
||||||
|
|
||||||
public static final int MAX_DATA_COUNT = 3;
|
public static final int MAX_DATA_COUNT = 3;
|
||||||
|
|
||||||
private LazyOptional<EnergyStorage> energyHandler;
|
private LazyOptional<EnergyStorage> energyHandler;
|
||||||
|
@ -78,7 +80,15 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider {
|
||||||
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, FuMO25BlockEntity blockEntity) {
|
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, FuMO25BlockEntity blockEntity) {
|
||||||
int energy = blockEntity.energyHandler.map(EnergyStorage::getEnergyStored).orElse(0);
|
int energy = blockEntity.energyHandler.map(EnergyStorage::getEnergyStored).orElse(0);
|
||||||
|
|
||||||
if (energy <= 0) {
|
FuncType funcType = blockEntity.type;
|
||||||
|
int energyCost;
|
||||||
|
if (funcType == FuncType.WIDER) {
|
||||||
|
energyCost = MAX_ENERGY_COST;
|
||||||
|
} else {
|
||||||
|
energyCost = DEFAULT_ENERGY_COST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (energy < energyCost) {
|
||||||
if (pState.getValue(FuMO25Block.POWERED)) {
|
if (pState.getValue(FuMO25Block.POWERED)) {
|
||||||
pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, false));
|
pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, false));
|
||||||
setChanged(pLevel, pPos, pState);
|
setChanged(pLevel, pPos, pState);
|
||||||
|
@ -89,22 +99,16 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!pState.getValue(FuMO25Block.POWERED)) {
|
if (!pState.getValue(FuMO25Block.POWERED)) {
|
||||||
pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, true));
|
if (energy >= DEFAULT_MIN_ENERGY) {
|
||||||
setChanged(pLevel, pPos, pState);
|
pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, true));
|
||||||
}
|
setChanged(pLevel, pPos, pState);
|
||||||
|
}
|
||||||
FuncType funcType = blockEntity.type;
|
|
||||||
int energyCost;
|
|
||||||
if (funcType == FuncType.WIDER) {
|
|
||||||
energyCost = MAX_ENERGY_COST;
|
|
||||||
} else {
|
} else {
|
||||||
energyCost = DEFAULT_ENERGY_COST;
|
blockEntity.energyHandler.ifPresent(handler -> handler.extractEnergy(energyCost, false));
|
||||||
}
|
if (blockEntity.time > 0) {
|
||||||
blockEntity.energyHandler.ifPresent(handler -> handler.extractEnergy(energyCost, false));
|
blockEntity.time--;
|
||||||
|
blockEntity.setChanged();
|
||||||
if (blockEntity.time > 0) {
|
}
|
||||||
blockEntity.time--;
|
|
||||||
blockEntity.setChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -633,8 +633,12 @@ public class FuMO25Model<T extends Entity> extends EntityModel<T> {
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 添加旋转
|
|
||||||
public void render(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha, boolean roll) {
|
public void render(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha, boolean roll) {
|
||||||
|
if (roll) {
|
||||||
|
this.yundongjian.yRot = (System.currentTimeMillis() % 36000000) / 1200f;
|
||||||
|
} else {
|
||||||
|
this.yundongjian.yRot = 0;
|
||||||
|
}
|
||||||
renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.client.renderer.block;
|
package com.atsuishio.superbwarfare.client.renderer.block;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.block.FuMO25Block;
|
||||||
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||||
import com.atsuishio.superbwarfare.client.model.block.FuMO25Model;
|
import com.atsuishio.superbwarfare.client.model.block.FuMO25Model;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
@ -32,7 +33,8 @@ public class FuMO25BlockEntityRenderer implements BlockEntityRenderer<FuMO25Bloc
|
||||||
pPoseStack.translate(0.5f, 2.7f, 0.5f);
|
pPoseStack.translate(0.5f, 2.7f, 0.5f);
|
||||||
|
|
||||||
VertexConsumer vertexconsumer = ItemRenderer.getFoilBufferDirect(pBuffer, this.model.renderType(TEXTURE), false, false);
|
VertexConsumer vertexconsumer = ItemRenderer.getFoilBufferDirect(pBuffer, this.model.renderType(TEXTURE), false, false);
|
||||||
this.model.render(pPoseStack, vertexconsumer, 0xffffff, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F, true);
|
this.model.render(pPoseStack, vertexconsumer, 0xffffff, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F,
|
||||||
|
pBlockEntity.getBlockState().getValue(FuMO25Block.POWERED));
|
||||||
pPoseStack.popPose();
|
pPoseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue