Some fixes to linking

This commit is contained in:
Calclavia 2014-01-28 17:26:40 +08:00
parent c37abd0ee5
commit 053236fa1f
5 changed files with 43 additions and 23 deletions

View file

@ -11,12 +11,13 @@ import org.modstats.ModstatInfo;
import org.modstats.Modstats; import org.modstats.Modstats;
import resonantinduction.core.handler.FluidEventHandler; import resonantinduction.core.handler.FluidEventHandler;
import resonantinduction.core.handler.LinkEventHandler; import resonantinduction.core.handler.ToolModeLink;
import resonantinduction.core.prefab.part.PacketMultiPart; import resonantinduction.core.prefab.part.PacketMultiPart;
import resonantinduction.core.resource.ResourceGenerator; import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture; import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.core.resource.fluid.TileLiquidMixture; import resonantinduction.core.resource.fluid.TileLiquidMixture;
import resonantinduction.core.resource.item.ItemOreResource; import resonantinduction.core.resource.item.ItemOreResource;
import calclavia.components.tool.ToolMode;
import calclavia.lib.content.ContentRegistry; import calclavia.lib.content.ContentRegistry;
import calclavia.lib.network.PacketHandler; import calclavia.lib.network.PacketHandler;
import calclavia.lib.network.PacketTile; import calclavia.lib.network.PacketTile;
@ -81,11 +82,12 @@ public class ResonantInduction
ResonantInduction.LOGGER.setParent(FMLLog.getLogger()); ResonantInduction.LOGGER.setParent(FMLLog.getLogger());
NetworkRegistry.instance().registerGuiHandler(this, proxy); NetworkRegistry.instance().registerGuiHandler(this, proxy);
Modstats.instance().getReporter().registerMod(this); Modstats.instance().getReporter().registerMod(this);
ToolMode.REGISTRY.add(new ToolModeLink());
Settings.load(); Settings.load();
// Register Forge Events // Register Forge Events
MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE); MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE);
MinecraftForge.EVENT_BUS.register(new LinkEventHandler());
MinecraftForge.EVENT_BUS.register(new FluidEventHandler()); MinecraftForge.EVENT_BUS.register(new FluidEventHandler());
fluidMixture = new Fluid("water"); fluidMixture = new Fluid("water");

View file

@ -3,52 +3,68 @@
*/ */
package resonantinduction.core.handler; package resonantinduction.core.handler;
import calclavia.components.tool.ToolMode;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import universalelectricity.api.vector.VectorWorld; import universalelectricity.api.vector.VectorWorld;
import calclavia.components.event.MultitoolEvent;
import codechicken.multipart.ControlKeyModifer; import codechicken.multipart.ControlKeyModifer;
/** /**
* @author Calclavia * @author Calclavia
*/ */
public class LinkEventHandler public class ToolModeLink extends ToolMode
{ {
@ForgeSubscribe @Override
public void linkEvent(MultitoolEvent evt) public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{ {
if (ControlKeyModifer.isControlDown(evt.player)) TileEntity tile = world.getBlockTileEntity(x, y, z);
{
TileEntity tile = evt.world.getBlockTileEntity(evt.x, evt.y, evt.z);
if (tile instanceof ILinkable && this.hasLink(evt.toolStack)) if (ControlKeyModifer.isControlDown(player))
{ {
if (!evt.world.isRemote) if (tile instanceof ILinkable)
{ {
if (((ILinkable) tile).onLink(evt.player, this.getLink(evt.toolStack))) if (!world.isRemote)
{ {
this.clearLink(evt.toolStack); if (((ILinkable) tile).onLink(player, this.getLink(stack)))
evt.player.addChatMessage("Link cleared."); {
clearLink(stack);
player.addChatMessage("Link cleared.");
return true;
} }
} }
evt.setResult(Result.DENY);
}
else
{
if (!evt.world.isRemote)
{
evt.player.addChatMessage("Set link to block [" + evt.x + ", " + evt.y + ", " + evt.z + "], Dimension: '" + evt.world.provider.getDimensionName() + "'");
this.setLink(evt.toolStack, new VectorWorld(evt.world, evt.x, evt.y, evt.z));
} }
} }
evt.setCanceled(true); if (!world.isRemote)
{
player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], Dimension: '" + world.provider.getDimensionName() + "'");
setLink(stack, new VectorWorld(world, x, y, z));
if (tile instanceof ILinkable)
{
if (!world.isRemote)
{
((ILinkable) tile).onLink(player, this.getLink(stack));
} }
} }
return true;
}
return false;
}
@Override
public String getName()
{
return "toolmode.link.name";
}
public boolean hasLink(ItemStack itemStack) public boolean hasLink(ItemStack itemStack)
{ {
return getLink(itemStack) != null; return getLink(itemStack) != null;
@ -78,4 +94,5 @@ public class LinkEventHandler
{ {
itemStack.getTagCompound().removeTag("link"); itemStack.getTagCompound().removeTag("link");
} }
} }

View file

@ -32,7 +32,7 @@ public class BlockBattery extends BlockIOBase implements ITileEntityProvider
public BlockBattery() public BlockBattery()
{ {
super("battery", Settings.getNextBlockID()); super("battery", Settings.getNextBlockID());
this.setTextureName(Reference.PREFIX + "machine"); this.setTextureName(Reference.PREFIX + "material_metal_side");
} }
@Override @Override

View file

@ -94,7 +94,7 @@ public class PartGearShaft extends PartMechanical
IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(checkDir.getOpposite()); IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(checkDir.getOpposite());
// Only connect to shafts outside of this block space. // Only connect to shafts outside of this block space.
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && instance instanceof PartGearShaft) if (instance != null && instance != this && instance instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
{ {
connections[checkDir.ordinal()] = instance; connections[checkDir.ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());

View file

@ -8,6 +8,7 @@ meta.resonantinduction.description=Resonant Induction is a Minecraft mod focusin
meta.resonantinduction.credits=Visit website for credits. meta.resonantinduction.credits=Visit website for credits.
fluid.mixture=Mixture fluid.mixture=Mixture
toolmode.link.name=Linking
### Core ### Core
misc.resonantinduction.ingot=Ingot misc.resonantinduction.ingot=Ingot