mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-24 06:04:38 +00:00
Fix top slabs (Closes #127) and rewrite slab placement code
This commit is contained in:
1 parent
a296ca0cae
commit
43eb12ef77
4 files changed
+83
-115
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package com.cricketcraft.chisel.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.block.BlockCarvableSlab;
|
||||
|
||||
public class ItemCarvableSlab extends ItemCarvable {
|
||||
|
||||
public ItemCarvableSlab(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hx, float hy, float hz) {
|
||||
BlockCarvableSlab block = (BlockCarvableSlab) Block.getBlockFromItem(this);
|
||||
int meta = stack.getItemDamage();
|
||||
|
||||
ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[side];
|
||||
Block clicked = world.getBlock(x, y, z);
|
||||
|
||||
// the position of the block that we are attempting to place at
|
||||
int x2 = x + dir.offsetX;
|
||||
int y2 = y + dir.offsetY;
|
||||
int z2 = z + dir.offsetZ;
|
||||
|
||||
Block at = world.getBlock(x2, y2, z2);
|
||||
|
||||
boolean metaEquals = world.getBlockMetadata(x2, y2, z2) == meta;
|
||||
// if the metadata at the place target matches, and the block there matches either the top of bottom slab, try to fill in the rest of the block
|
||||
if (metaEquals && ((at == block.top && (dir == ForgeDirection.DOWN || hy == 1.0D)) || (at == block.bottom && (dir == ForgeDirection.UP || hy == 0)))) {
|
||||
place(stack, world, x2, y2, z2, block.master, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
// else if the block clicked on is a top or bottom slab of this type, try to fill in that block if possible
|
||||
boolean clickedMetaEquals = world.getBlockMetadata(x, y, z) == meta;
|
||||
if (clickedMetaEquals && ((clicked == block.bottom && dir == ForgeDirection.UP) || (clicked == block.top && dir == ForgeDirection.DOWN))) {
|
||||
place(stack, world, x, y, z, block.master, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
// finally just try to place a normal slab
|
||||
if (metaEquals || at.isReplaceable(world, x, y, z)) {
|
||||
boolean top = hy > 0.5D && dir != ForgeDirection.UP || dir == ForgeDirection.DOWN;
|
||||
Block toPlace = top ? block.top : block.bottom;
|
||||
// if we can replace the clicked block do so
|
||||
if (clicked.isReplaceable(world, x, y, z)) {
|
||||
place(stack, world, x, y, z, toPlace, meta);
|
||||
} else {
|
||||
place(stack, world, x2, y2, z2, toPlace, meta);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void place(ItemStack stack, World world, int x, int y, int z, Block toPlace, int metadata) {
|
||||
world.setBlock(x, y, z, toPlace, metadata, 2);
|
||||
stack.stackSize -= 1;
|
||||
world.playSoundEffect(x + 0.5f, y + 0.5f, z + 0.5f, this.field_150939_a.stepSound.func_150496_b(), (this.field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F,
|
||||
this.field_150939_a.stepSound.getPitch() * 0.8F);
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package com.cricketcraft.chisel.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.cricketcraft.chisel.block.BlockCarvableSlab;
|
||||
|
||||
public class ItemMarbleSlab extends ItemCarvable {
|
||||
|
||||
public ItemMarbleSlab(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
|
||||
BlockCarvableSlab block = (BlockCarvableSlab) Block.getBlockFromItem(this);
|
||||
|
||||
switch (side) {
|
||||
case 0:
|
||||
--y;
|
||||
break;
|
||||
case 1:
|
||||
++y;
|
||||
break;
|
||||
case 2:
|
||||
--z;
|
||||
break;
|
||||
case 3:
|
||||
++z;
|
||||
break;
|
||||
case 4:
|
||||
--x;
|
||||
break;
|
||||
case 5:
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
return (targetBlock.equals(block) || targetBlock.equals(block.top)) && meta == stack.getItemDamage() || world.canPlaceEntityOnSide(block, x, y, z, false, side, (Entity) null, stack);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hx, float hy, float hz) {
|
||||
BlockCarvableSlab block = (BlockCarvableSlab) Block.getBlockFromItem(this);
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
boolean metaMatches = meta == stack.getItemDamage();
|
||||
|
||||
if (metaMatches && side == 0 && targetBlock.equals(block.top)) {
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
stack.stackSize -= 1;
|
||||
return true;
|
||||
} else if (metaMatches && side == 1 && targetBlock.equals(block.bottom)) {
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
stack.stackSize -= 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean result = super.onItemUse(stack, player, world, x, y, z, side, hz, hy, hz);
|
||||
|
||||
switch (side) {
|
||||
case 0:
|
||||
--y;
|
||||
break;
|
||||
case 1:
|
||||
++y;
|
||||
break;
|
||||
case 2:
|
||||
--z;
|
||||
break;
|
||||
case 3:
|
||||
++z;
|
||||
break;
|
||||
case 4:
|
||||
--x;
|
||||
break;
|
||||
case 5:
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
|
||||
targetBlock = world.getBlock(x, y, z);
|
||||
meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if (!result && (targetBlock.equals(block.top) || targetBlock.equals(block.bottom)) && meta == stack.getItemDamage()) {
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if (side != 0 && (side == 1 || hy <= 0.5D))
|
||||
return true;
|
||||
|
||||
// TODO allow top slabs
|
||||
// world.setBlock(x, y, z, block.top, meta, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user