From 37b18d77f4e341f338ee19c118bb32c969cd90f8 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 26 Mar 2014 22:27:14 -0500 Subject: [PATCH] Fix Block Cable Painting Support. --- block/networking/BlockCableBus.java | 7 +++++- me/cache/SecurityCache.java | 2 +- parts/CableBusContainer.java | 5 ++-- parts/ICableBusContainer.java | 2 +- parts/NullCableBusContainer.java | 2 +- parts/networking/PartCable.java | 38 ++++++++++++++++++++++++++--- 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/block/networking/BlockCableBus.java b/block/networking/BlockCableBus.java index d659f94fa..bfa679c08 100644 --- a/block/networking/BlockCableBus.java +++ b/block/networking/BlockCableBus.java @@ -57,10 +57,15 @@ public class BlockCableBus extends AEBaseBlock @Override public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) + { + return recolourBlock( world, x, y, z, side, colour, null ); + } + + public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour, EntityPlayer who) { try { - return cb( world, x, y, z ).recolourBlock( side, colour ); + return cb( world, x, y, z ).recolourBlock( side, colour, who ); } catch (Throwable t) { diff --git a/me/cache/SecurityCache.java b/me/cache/SecurityCache.java index 1015f62ac..6b61023a0 100644 --- a/me/cache/SecurityCache.java +++ b/me/cache/SecurityCache.java @@ -56,7 +56,7 @@ public class SecurityCache implements IGridCache, ISecurityGrid @Override public boolean hasPermission(EntityPlayer player, SecurityPermissions perm) { - return hasPermission( WorldSettings.getInstance().getPlayerID( player.getCommandSenderName() ), perm ); + return hasPermission( player == null ? -1 : WorldSettings.getInstance().getPlayerID( player.getCommandSenderName() ), perm ); } @Override diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index bb2f7678a..169da6041 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -782,7 +782,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer return light; } - public boolean recolourBlock(ForgeDirection side, int colour) + @Override + public boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who) { IPart cable = getPart( ForgeDirection.UNKNOWN ); if ( cable != null ) @@ -791,7 +792,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer AEColor colors[] = AEColor.values(); if ( colors.length > colour ) - return pc.changeColor( colors[colour] ); + return pc.changeColor( colors[colour], who ); } return false; } diff --git a/parts/ICableBusContainer.java b/parts/ICableBusContainer.java index a18888357..f74be2b6f 100644 --- a/parts/ICableBusContainer.java +++ b/parts/ICableBusContainer.java @@ -34,7 +34,7 @@ public interface ICableBusContainer SelectedPart selectPart(Vec3 v3); - boolean recolourBlock(ForgeDirection side, int colour); + boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who); boolean isLadder(EntityLivingBase entity); diff --git a/parts/NullCableBusContainer.java b/parts/NullCableBusContainer.java index caba57f51..a0fdad011 100644 --- a/parts/NullCableBusContainer.java +++ b/parts/NullCableBusContainer.java @@ -69,7 +69,7 @@ public class NullCableBusContainer implements ICableBusContainer } @Override - public boolean recolourBlock(ForgeDirection side, int colour) + public boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who) { return false; } diff --git a/parts/networking/PartCable.java b/parts/networking/PartCable.java index 6fde9f8a5..e6fea62c0 100644 --- a/parts/networking/PartCable.java +++ b/parts/networking/PartCable.java @@ -7,6 +7,7 @@ import java.util.EnumSet; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; @@ -15,6 +16,7 @@ import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; import appeng.api.AEApi; +import appeng.api.config.SecurityPermissions; import appeng.api.implementations.parts.IPartCable; import appeng.api.networking.GridFlags; import appeng.api.networking.IGridConnection; @@ -879,13 +881,41 @@ public class PartCable extends AEBasePart implements IPartCable } @Override - public boolean changeColor(AEColor newColor) + public boolean changeColor(AEColor newColor, EntityPlayer who) { if ( getCableColor() != newColor ) { - is.setItemDamage( newColor.ordinal() ); - markForUpdate(); - return true; + ItemStack newPart = null; + + if ( getCableConnectionType() == AECableType.GLASS ) + newPart = AEApi.instance().parts().partCableGlass.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.COVERED ) + newPart = AEApi.instance().parts().partCableCovered.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.SMART ) + newPart = AEApi.instance().parts().partCableSmart.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.DENSE ) + newPart = AEApi.instance().parts().partCableDense.stack( newColor, 1 ); + + boolean hasPermission = true; + + try + { + hasPermission = proxy.getSecurity().hasPermission( who, SecurityPermissions.BUILD ); + } + catch (GridAccessException e) + { + // :P + } + + if ( newPart != null && hasPermission ) + { + if ( Platform.isClient() ) + return true; + + getHost().removePart( ForgeDirection.UNKNOWN, false ); + getHost().addPart( newPart, ForgeDirection.UNKNOWN, who ); + return true; + } } return false; }