commit 49d269ace3d79434b92c0c26be48cd55e4c0f51f
parent 8153b31aa2e92500e68d877587e3a23a892db9c6
Author: Amb0s <ambos@disroot.org>
Date: Sun, 4 Feb 2024 22:11:10 +0100
Tweaked texture, drop and placement logic
Diffstat:
1 file changed, 34 insertions(+), 9 deletions(-)
diff --git a/src/main/java/turniplabs/simpletech/block/BlockRedstoneNotGate.java b/src/main/java/turniplabs/simpletech/block/BlockRedstoneNotGate.java
@@ -1,9 +1,11 @@
package turniplabs.simpletech.block;
import net.minecraft.core.block.Block;
+import net.minecraft.core.block.entity.TileEntity;
import net.minecraft.core.block.material.Material;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.enums.EnumDropCause;
+import net.minecraft.core.item.ItemStack;
import net.minecraft.core.util.helper.Side;
import net.minecraft.core.world.World;
import net.minecraft.core.world.WorldSource;
@@ -40,6 +42,22 @@ public class BlockRedstoneNotGate extends Block {
public boolean renderAsNormalBlock() {
return false;
}
+
+ @Override
+ public boolean canPlaceBlockAt(World world, int x, int y, int z) {
+ return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canPlaceBlockAt(world, x, y, z);
+ }
+
+ @Override
+ public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) {
+ return new ItemStack[]{new ItemStack(SimpleTech.notGate)};
+ }
+
+ @Override
+ public boolean canBlockStay(World world, int x, int y, int z) {
+ return !world.canPlaceOnSurfaceOfBlock(x, y - 1, z) ? false : super.canBlockStay(world, x, y, z);
+ }
+
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
int l = world.getBlockMetadata(x, y, z);
@@ -50,24 +68,28 @@ public class BlockRedstoneNotGate extends Block {
world.setBlockAndMetadataWithNotify(x, y, z, SimpleTech.notGateActive.id, l);
}
}
+
@Override
public int getBlockTextureFromSideAndMetadata(Side side, int j) {
if (side == Side.BOTTOM) {
- return !this.isPowered ? texCoordToIndex(3, 7) : texCoordToIndex(3, 6);
- } else if (side == Side.TOP) {
- return !this.isPowered ? texCoordToIndex(3, 8) : texCoordToIndex(3, 9);
- } else {
+ return this.atlasIndices[Side.TOP.getId()]; // Defaults to top/bottom texture.
+ } else if (side == Side.TOP) {
+ return this.atlasIndices[Side.TOP.getId()]; // Defaults to top/bottom texture.
+ } else {
return texCoordToIndex(5, 0);
- }
+ }
}
+
@Override
public boolean shouldSideBeRendered(WorldSource blockAccess, int x, int y, int z, int side) {
- return side != 0 && side != 1;
+ return side != 0 && side != 1; // Don't render bottom and top textures to avoid z-fighting with modified renderer.
}
+
@Override
public boolean isIndirectlyPoweringTo(World world, int x, int y, int z, int side) {
return this.isPoweringTo(world, x, y, z, side);
}
+
@Override
public boolean isPoweringTo(WorldSource blockAccess, int x, int y, int z, int side) {
if (!this.isPowered) {
@@ -81,10 +103,11 @@ public class BlockRedstoneNotGate extends Block {
} else if (direction == 2 && side == 2) {
return false;
} else {
- return !(direction == 3 && side == 5);
+ return false;
}
}
}
+
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) {
if (!this.canBlockStay(world, x, y, z)) {
@@ -93,7 +116,6 @@ public class BlockRedstoneNotGate extends Block {
} else {
int i1 = world.getBlockMetadata(x, y, z);
boolean flag = this.unknown(world, x, y, z, i1);
- int j1 = (i1 & 12) >> 2;
if (this.isPowered && !flag) {
world.scheduleBlockUpdate(x, y, z, this.id, 1);
} else if (!this.isPowered && flag) {
@@ -125,19 +147,22 @@ public class BlockRedstoneNotGate extends Block {
return false;
}
}
+
@Override
public boolean canProvidePower() {
return false;
}
+
@Override
public void onBlockPlaced(World world, int x, int y, int z, Side side, EntityLiving entity, double sideHeight) {
- int l = entity.getHorizontalPlacementDirection(side).index;
+ int l = entity.getHorizontalPlacementDirection(side).getHorizontalIndex();
world.setBlockMetadataWithNotify(x, y, z, l);
boolean flag = this.unknown(world, x, y, z, l);
if (flag) {
world.scheduleBlockUpdate(x, y, z, this.id, 1);
}
}
+
@Override
public void onBlockAdded(World world, int i, int j, int k) {
world.notifyBlocksOfNeighborChange(i + 1, j, k, this.id);