Added add/remove of plugs, fixed plug render sync issue, fix renderer, prevent render of gate on plugged sides

This commit is contained in:
Krapht 2013-05-07 20:48:19 +02:00
parent b39802f210
commit fdd5648a05
4 changed files with 61 additions and 9 deletions

View file

@ -1,8 +1,11 @@
package buildcraft.transport;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemBuildCraft;
import cpw.mods.fml.relauncher.Side;
@ -20,6 +23,31 @@ public class ItemPlug extends ItemBuildCraft {
return "item.PipePlug";
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (worldObj.isRemote)
return false;
TileEntity tile = worldObj.getBlockTileEntity(x, y, z);
if (!(tile instanceof TileGenericPipe))
return false;
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (player.isSneaking()) { // Strip plug
if (!pipeTile.hasPlug(ForgeDirection.VALID_DIRECTIONS[side]))
return false;
pipeTile.removeAndDropPlug(ForgeDirection.VALID_DIRECTIONS[side]);
return true;
} else {
if (((TileGenericPipe) tile).addPlug(ForgeDirection.VALID_DIRECTIONS[side])){
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return true;
}
return false;
}
}
@Override
public boolean shouldPassSneakingClickToBlock(World worldObj, int x, int y, int z ) {
return true;

View file

@ -461,6 +461,9 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
if (container.hasFacade(direction)) {
container.dropFacade(direction);
}
if (container.hasPlug(direction)){
container.removeAndDropPlug(direction);
}
}
if (broadcastRedstone) {

View file

@ -253,16 +253,15 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
renderState.facadeMatrix.setFacade(direction, blockId, this.facadeMeta[direction.ordinal()]);
}
if (renderState.isDirty()) {
worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
renderState.clean();
}
//Plugs
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS){
renderState.plugMatrix.setConnected(direction, plugs[direction.ordinal()]);
}
if (renderState.isDirty()) {
worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
renderState.clean();
}
}
public void initialize(Pipe pipe) {
@ -690,4 +689,26 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
}
return false;
}
public boolean hasPlug(ForgeDirection forgeDirection) {
return plugs[forgeDirection.ordinal()];
}
public void removeAndDropPlug(ForgeDirection forgeDirection) {
if (!hasPlug(forgeDirection)) return;
plugs[forgeDirection.ordinal()] = false;
Utils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord);
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord));
scheduleRenderUpdate();
}
public boolean addPlug(ForgeDirection forgeDirection) {
if (hasPlug(forgeDirection)) return false;
plugs[forgeDirection.ordinal()] = true;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord));
scheduleRenderUpdate();
return true;
}
}

View file

@ -358,8 +358,8 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
zeroState[0][0] = 0.25F - zFightOffset / 2;
zeroState[0][1] = 0.75F + zFightOffset / 2;
// Y START - END
zeroState[1][0] = 0.75F;
zeroState[1][1] = 0.875F - zFightOffset;
zeroState[1][0] = 0.125F;
zeroState[1][1] = 0.25F;
// Z START - END
zeroState[2][0] = 0.25F;
zeroState[2][1] = 0.75F;
@ -549,7 +549,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
}
private boolean shouldRenderNormalPipeSide(PipeRenderState state, ForgeDirection direction){
return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0;
return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0 && !state.plugMatrix.isConnected(direction);
}
@Override