use of pl.asie.charset.module.transport.carts.link.Linkable in project Charset by CharsetMC.
the class CharsetTransportCarts method preInit.
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
CapabilityManager.INSTANCE.register(Linkable.class, Linkable.STORAGE, Linkable::new);
if (ModCharset.profile.includes(ModuleProfile.INDEV)) {
linker = new TrainLinker();
MinecraftForge.EVENT_BUS.register(linker);
itemLinker = new Item().setCreativeTab(ModCharset.CREATIVE_TAB).setUnlocalizedName("linker").setMaxStackSize(1);
}
combiner = new TrackCombiner();
}
use of pl.asie.charset.module.transport.carts.link.Linkable in project Charset by CharsetMC.
the class CharsetTransportCarts method onEntityInteract.
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
if (event.getTarget() instanceof EntityMinecart && !event.getTarget().getEntityWorld().isRemote && event.getItemStack().getItem() == itemLinker) {
EntityMinecart cart = (EntityMinecart) event.getTarget();
if (linkMap.containsKey(event.getEntityPlayer())) {
EntityMinecart cartOther = linkMap.remove(event.getEntityPlayer());
Linkable link = linker.get(cart);
Linkable linkOther = linker.get(cartOther);
if (event.getEntityPlayer().isSneaking()) {
if (linker.unlink(link, linkOther)) {
event.getEntityPlayer().sendMessage(new TextComponentString("dev_unlinked2"));
} else {
event.getEntityPlayer().sendMessage(new TextComponentString("dev_unlink2_failed"));
}
} else {
if (link.next == null && linkOther.previous == null) {
linker.link(link, linkOther);
event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked2"));
} else if (link.previous == null && linkOther.next == null) {
linker.link(linkOther, link);
event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked2"));
} else {
event.getEntityPlayer().sendMessage(new TextComponentString("dev_link2_failed"));
}
}
} else {
linkMap.put(event.getEntityPlayer(), cart);
event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked1"));
}
event.setCanceled(true);
}
}
Aggregations