Switch Wires! and finish respecting creative-mode players (don't use/drop items)

This commit is contained in:
Alex_hawks 2013-12-30 15:07:44 +08:00
parent eb75c2b7d1
commit b33f13de2c
4 changed files with 108 additions and 7 deletions

View file

@ -2,6 +2,7 @@ package resonantinduction;
import resonantinduction.multimeter.PartMultimeter;
import resonantinduction.transformer.PartTransformer;
import resonantinduction.wire.part.PartFlatSwitchWire;
import resonantinduction.wire.part.PartFlatWire;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
@ -14,7 +15,7 @@ public class MultipartRI implements IPartFactory
public MultipartRI()
{
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire", "resonant_induction_multimeter", "resonant_induction_transformer" });
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire", "resonant_induction_flat_switch_wire", "resonant_induction_multimeter", "resonant_induction_transformer" });
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
MultipartGenerator.registerTrait("cofh.api.energy.IEnergyHandler", "resonantinduction.wire.part.TraitEnergyHandler");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
@ -27,6 +28,10 @@ public class MultipartRI implements IPartFactory
{
return new PartFlatWire();
}
else if(name.equals("resonant_induction_flat_switch_wire"))
{
return new PartFlatSwitchWire();
}
else if (name.equals("resonant_induction_multimeter"))
{
return new PartMultimeter();

View file

@ -8,7 +8,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -16,7 +15,6 @@ import net.minecraft.util.MovingObjectPosition;
import resonantinduction.Utility;
import resonantinduction.wire.EnumWireMaterial;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.energy.IConductor;
import calclavia.lib.prefab.CustomDamageSource;
import codechicken.lib.data.MCDataInput;
@ -217,7 +215,7 @@ public abstract class PartAdvancedWire extends PartConductor
}
else if (itemStack.getItem() instanceof ItemShears && isInsulated())
{
if (!world().isRemote)
if (!world().isRemote && !player.capabilities.isCreativeMode)
{
tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(color))));
}

View file

@ -0,0 +1,66 @@
package resonantinduction.wire.part;
import java.util.Collections;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TileMultipart;
public class PartFlatSwitchWire extends PartFlatWire
{
@Override
public boolean canConnectTo(Object obj)
{
if (this.world().isBlockIndirectlyGettingPowered(x(), y(), z()))
return super.canConnectTo(obj);
return false;
}
@Override
public String getType()
{
return "resonant_induction_flat_switch_wire";
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{
TileMultipart tile = tile();
World w = world();
if (item.getItem().itemID == Block.lever.blockID)
{
if (!w.isRemote)
{
PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false);
wire.isInsulated = this.isInsulated;
wire.color = this.color;
wire.connections = this.connections;
wire.material = this.material;
wire.side = this.side;
wire.connMap = this.connMap;
if (tile.canReplacePart(this, wire))
{
tile.remPart(this);
TileMultipart.addPart(w, new BlockCoord(tile), wire);
if (!player.capabilities.isCreativeMode)
{
tile.dropItems(Collections.singletonList(new ItemStack(Block.lever, 1)));
}
}
}
return true;
}
else
{
return super.activate(player, part, item);
}
}
}

View file

@ -2,6 +2,7 @@ package resonantinduction.wire.part;
import java.util.Arrays;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -9,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
@ -29,6 +31,7 @@ import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.PartMap;
import codechicken.multipart.TFacePart;
@ -271,15 +274,44 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
super.onNeighborChanged();
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{
if (!world().isRemote)
{
System.out.println(this.getNetwork());
}
return super.activate(player, part, item);
TileMultipart tile = tile();
World w = world();
if (item.getItem().itemID == Block.lever.blockID)
{
if (!w.isRemote)
{
PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_switch_wire", false);
wire.isInsulated = this.isInsulated;
wire.color = this.color;
wire.connections = this.connections;
wire.material = this.material;
wire.side = this.side;
wire.connMap = this.connMap;
if (tile.canReplacePart(this, wire))
{
tile.remPart(this);
TileMultipart.addPart(w, new BlockCoord(tile), wire);
if (!player.capabilities.isCreativeMode)
{
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
}
}
return true;
}
else
{
return super.activate(player, part, item);
}
}
@Override