Skip to content

Commit

Permalink
fix: TileEntityMachineBase#isGettingPower wasn't changed on the clien…
Browse files Browse the repository at this point in the history
…t side
  • Loading branch information
Kai-Z-JP committed Feb 5, 2025
1 parent 86bcd4e commit 1f4f9ab
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 53 deletions.
15 changes: 0 additions & 15 deletions src/main/java/jp/ngt/rtm/block/BlockCrossingGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jp.ngt.rtm.RTMItem;
import jp.ngt.rtm.block.tileentity.TileEntityCrossingGate;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
Expand All @@ -27,18 +26,4 @@ public void dropBlockAsItemWithChance(World world, int x, int y, int z, int par5
this.dropBlockAsItem(world, x, y, z, new ItemStack(RTMItem.installedObject, 1, 5));
}
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
super.onNeighborBlockChange(world, x, y, z, block);
TileEntityCrossingGate tile = (TileEntityCrossingGate) world.getTileEntity(x, y, z);
tile.isGettingPower = world.isBlockIndirectlyGettingPowered(x, y, z);
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
TileEntityCrossingGate tile = (TileEntityCrossingGate) world.getTileEntity(x, y, z);
tile.isGettingPower = world.isBlockIndirectlyGettingPowered(x, y, z);
}
}
24 changes: 0 additions & 24 deletions src/main/java/jp/ngt/rtm/block/BlockLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jp.ngt.rtm.RTMCore;
import jp.ngt.rtm.RTMItem;
import jp.ngt.rtm.block.tileentity.TileEntityLight;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -37,29 +36,6 @@ public void dropBlockAsItemWithChance(World world, int par2, int par3, int par4,
}
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
super.onNeighborBlockChange(world, x, y, z, block);
this.updateBlockState(world, x, y, z);
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.updateBlockState(world, x, y, z);
}

protected void updateBlockState(World world, int x, int y, int z) {
TileEntityLight tile = (TileEntityLight) world.getTileEntity(x, y, z);
tile.isGettingPower = world.isBlockIndirectlyGettingPowered(x, y, z);

boolean b = world.isBlockIndirectlyGettingPowered(x, y, z);
if (tile.isGettingPower ^ b) {
tile.isGettingPower = b;
world.func_147451_t(x, y, z);//明るさ更新
}
}

@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if (world.isRemote || PermissionManager.INSTANCE.hasPermission(player, RTMCore.EDIT_ORNAMENT)) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/jp/ngt/rtm/block/BlockMachineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jp.ngt.rtm.item.ItemInstalledObject;
import jp.ngt.rtm.item.ItemWithModel;
import jp.ngt.rtm.modelpack.cfg.MachineConfig;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -89,4 +90,25 @@ public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, i
}
return null;
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
super.onNeighborBlockChange(world, x, y, z, block);
this.updateBlockState(world, x, y, z);
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.updateBlockState(world, x, y, z);
}

protected void updateBlockState(World world, int x, int y, int z) {
TileEntityMachineBase tile = (TileEntityMachineBase) world.getTileEntity(x, y, z);

boolean b = world.isBlockIndirectlyGettingPowered(x, y, z);
if (tile.isGettingPower ^ b) {
tile.setGettingPower(b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TileEntityCrossingGate extends TileEntityMachineBase {
public void updateEntity() {
super.updateEntity();

if (this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) {
if (this.isGettingPower) {
if (this.barMoveCount < 90) {
++this.barMoveCount;
}
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/jp/ngt/rtm/block/tileentity/TileEntityLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@ public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
}

// @Override
// public void updateEntity() {
// super.updateEntity();
//
// boolean b = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord);
// if (this.isGettingPower ^ b) {
// this.isGettingPower = b;
// this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord);//明るさ更新
// }
// }

@Override
public Vec3 getNormal(float x, float y, float z, float pitch, float yaw) {
if (this.normal == null) {
this.normal = Vec3.createVectorHelper(x, y, z);
MachinePartsRenderer.rotateVec(this.normal,
this.getBlockMetadata(), pitch, yaw);
MachinePartsRenderer.rotateVec(this.normal, this.getBlockMetadata(), pitch, yaw);
}
return this.normal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public void readFromNBT(NBTTagCompound nbt) {

this.yawFixed = nbt.hasKey("Yaw");
this.getResourceState().readFromNBT(nbt.getCompoundTag("State"));

boolean gettingPower = nbt.getBoolean("isGettingPower");
if (this.isGettingPower != gettingPower) {
this.isGettingPower = gettingPower;
if (this.worldObj != null) {
this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord);//明るさ更新
}
}
}

@Override
Expand All @@ -59,6 +67,7 @@ public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("ModelName", this.modelName);
nbt.setFloat("Pitch", this.pitch);
nbt.setTag("State", this.getResourceState().writeToNBT());
nbt.setBoolean("isGettingPower", this.isGettingPower);
}

@Override
Expand All @@ -73,6 +82,13 @@ public void updateEntity() {
}
}

public void setGettingPower(boolean par1) {
if (this.isGettingPower != par1) {
this.isGettingPower = par1;
this.markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}

@Override
public void setRotation(EntityPlayer player, float rotationInterval, boolean synch) {
Expand Down

0 comments on commit 1f4f9ab

Please sign in to comment.