本文整理汇总了Java中net.minecraftforge.event.entity.minecart.MinecartInteractEvent.setCanceled方法的典型用法代码示例。如果您正苦于以下问题:Java MinecartInteractEvent.setCanceled方法的具体用法?Java MinecartInteractEvent.setCanceled怎么用?Java MinecartInteractEvent.setCanceled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.event.entity.minecart.MinecartInteractEvent
的用法示例。
在下文中一共展示了MinecartInteractEvent.setCanceled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMinecartInteraction
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onMinecartInteraction(MinecartInteractEvent event){
if(!event.getMinecart().world.isRemote) {
ItemStack heldItem = event.getPlayer().getHeldItemMainhand();
if(!heldItem.isEmpty()) {
CapabilityMinecartDestination cap = event.getMinecart().getCapability(CapabilityMinecartDestination.INSTANCE, null);
if(cap != null) {
if(heldItem.getItem() == ModItems.CART_ENGINE && !cap.isMotorized()) {
if(!event.getPlayer().isCreative()) {
heldItem.shrink(1);
if(heldItem.isEmpty()) event.getPlayer().setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
cap.setMotorized();
event.getPlayer().sendMessage(new TextComponentTranslation("signals.message.cart_engine_installed"));
event.setCanceled(true);
} else if(heldItem.getItem() == ModItems.RAIL_CONFIGURATOR) {
RailCacheManager.syncStationNames((EntityPlayerMP)event.getPlayer());
event.getPlayer().openGui(Signals.instance, CommonProxy.EnumGuiId.MINECART_DESTINATION.ordinal(), ((EntityPlayerMP)event.getPlayer()).world, event.getMinecart().getEntityId(), -1, cap.isMotorized() ? 1 : 0);
event.setCanceled(true);
} else if(heldItem.getItem() == ModItems.TICKET) {
if(event.getPlayer().isSneaking()) {
ItemTicket.setDestinations(heldItem, Arrays.asList(cap.getDestinations()));
event.getPlayer().sendMessage(new TextComponentTranslation("signals.message.destinations_saved", TextFormatting.GOLD + ItemTicket.getConcattedDestinations(heldItem) + TextFormatting.WHITE));
} else {
ItemTicket.applyDestinations(event.getMinecart(), heldItem);
event.getPlayer().sendMessage(new TextComponentTranslation("signals.message.destinations_set", TextFormatting.GOLD + ItemTicket.getConcattedDestinations(heldItem) + TextFormatting.WHITE));
}
event.setCanceled(true);
}
}
}
}
}
示例2: MinecartInteractEvent
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void MinecartInteractEvent(MinecartInteractEvent event) {
if (event.entity instanceof EntityMinecartChest) {
ItemStack curItem = event.player.getCurrentEquippedItem();
EntityMinecartChest oldCart = (EntityMinecartChest) event.entity;
if (curItem != null && curItem.getItem() == WoodIronUpgrade) {
EntityIronChestCart ironCart = new EntityIronChestCart(oldCart.worldObj);
ironCart.copyDataFrom(event.entity, true);
ironCart.setDisplayTileData(0);
if (!event.entity.worldObj.isRemote) {
oldCart.worldObj.spawnEntityInWorld(ironCart);
}
for (int i = 0; i < oldCart.getSizeInventory(); i++) {
oldCart.setInventorySlotContents(i, null);
}
oldCart.setDead();
event.player.destroyCurrentEquippedItem();
event.setCanceled(true);
} else if (curItem != null && curItem.getItem() == WoodCopperUpgrade) {
EntityCopperChestCart copperCart = new EntityCopperChestCart(oldCart.worldObj);
copperCart.copyDataFrom(event.entity, true);
copperCart.setDisplayTileData(3);
if (!event.entity.worldObj.isRemote) {
oldCart.worldObj.spawnEntityInWorld(copperCart);
}
for (int i = 0; i < oldCart.getSizeInventory(); i++) {
oldCart.setInventorySlotContents(i, null);
}
oldCart.setDead();
event.player.destroyCurrentEquippedItem();
event.setCanceled(true);
}
}
}
示例3: onMinecartEvent
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onMinecartEvent(MinecartInteractEvent ev){
if(!Properties.enableMinecartTweaks)return; //ignore if turned off
EntityMinecart cart=ev.minecart;
if(cart instanceof EntityMinecartFurnace){
EntityPlayer player=ev.player;
if(player.isSneaking()){
//invert motion if player is sneaking - allows making furnace cart come
EntityMinecartFurnace fc=(EntityMinecartFurnace) cart;
fc.pushX = -(fc.posX - player.posX);
fc.pushZ = -(fc.posZ - player.posZ);
ev.setCanceled(true); //stop normal handling - we took care of it
}
}
}