Search in sources :

Example 1 with Linkable

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();
}
Also used : Item(net.minecraft.item.Item) Linkable(pl.asie.charset.module.transport.carts.link.Linkable) TrainLinker(pl.asie.charset.module.transport.carts.link.TrainLinker)

Example 2 with Linkable

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);
    }
}
Also used : Linkable(pl.asie.charset.module.transport.carts.link.Linkable) EntityMinecart(net.minecraft.entity.item.EntityMinecart) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Linkable (pl.asie.charset.module.transport.carts.link.Linkable)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 Item (net.minecraft.item.Item)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 TrainLinker (pl.asie.charset.module.transport.carts.link.TrainLinker)1