use of ValkyrienWarfareControl.Capability.ICapabilityLastRelay in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ControlEventsCommon method onAttachCapabilityEventItem.
@SubscribeEvent
public void onAttachCapabilityEventItem(AttachCapabilitiesEvent event) {
if (event instanceof AttachCapabilitiesEvent.Item) {
AttachCapabilitiesEvent.Item itemEvent = (AttachCapabilitiesEvent.Item) event;
ItemStack stack = itemEvent.getItemStack();
if (itemEvent.getItem() instanceof ItemRelayWire) {
// System.out.println("Obama?");
event.addCapability(new ResourceLocation(ValkyrienWarfareControlMod.MODID, "LastRelay"), new ICapabilitySerializable<NBTTagIntArray>() {
ICapabilityLastRelay inst = ValkyrienWarfareControlMod.lastRelayCapability.getDefaultInstance();
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == ValkyrienWarfareControlMod.lastRelayCapability;
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
return capability == ValkyrienWarfareControlMod.lastRelayCapability ? ValkyrienWarfareControlMod.lastRelayCapability.<T>cast(inst) : null;
}
@Override
public NBTTagIntArray serializeNBT() {
return (NBTTagIntArray) ValkyrienWarfareControlMod.lastRelayCapability.getStorage().writeNBT(ValkyrienWarfareControlMod.lastRelayCapability, inst, null);
}
@Override
public void deserializeNBT(NBTTagIntArray nbt) {
ValkyrienWarfareControlMod.lastRelayCapability.getStorage().readNBT(ValkyrienWarfareControlMod.lastRelayCapability, inst, null, nbt);
}
});
}
}
}
use of ValkyrienWarfareControl.Capability.ICapabilityLastRelay in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ItemRelayWire method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState clickedState = worldIn.getBlockState(pos);
Block block = clickedState.getBlock();
TileEntity currentTile = worldIn.getTileEntity(pos);
if (currentTile instanceof INodeProvider && !worldIn.isRemote) {
ICapabilityLastRelay inst = stack.getCapability(ValkyrienWarfareControlMod.lastRelayCapability, null);
if (inst != null) {
if (!inst.hasLastRelay()) {
inst.setLastRelay(pos);
//Draw a wire in the player's hand after this
} else {
BlockPos lastPos = inst.getLastRelay();
double distance = lastPos.distanceSq(pos);
TileEntity lastPosTile = worldIn.getTileEntity(lastPos);
if (!lastPos.equals(pos) && lastPosTile != null && currentTile != null) {
if (distance < range * range) {
Node lastPosNode = ((INodeProvider) lastPosTile).getNode();
Node currentPosNode = ((INodeProvider) currentTile).getNode();
//Connect the two bastards
// inst.setLastRelay(pos);
inst.setLastRelay(null);
if (lastPosNode != null && currentPosNode != null) {
currentPosNode.linkNode(lastPosNode);
}
// System.out.println("Success");
stack.damageItem(1, playerIn);
} else {
playerIn.addChatComponentMessage(new TextComponentString("Nodes are too far away, try better wire"));
inst.setLastRelay(null);
}
} else {
inst.setLastRelay(pos);
}
}
}
}
return EnumActionResult.FAIL;
}
Aggregations