use of net.minecraft.util.EnumActionResult in project Railcraft by Railcraft.
the class ItemChargeMeter method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (Game.isClient(world))
return EnumActionResult.PASS;
EnumActionResult returnValue = EnumActionResult.PASS;
ChargeNetwork.ChargeNode node = ChargeManager.getNetwork(world).getNode(pos);
if (!node.isNull() && !node.isGraphNull()) {
sendChat(player, "gui.railcraft.charge.meter.start", SECONDS_TO_RECORD);
node.startRecordingUsage(SECONDS_TO_RECORD * 20, (n, avg) -> {
ChargeNetwork.ChargeGraph graph = n.getChargeGraph();
sendChat(player, "gui.railcraft.charge.meter.network", graph.size(), graph.isInfinite() ? "INF" : graph.getCharge(), graph.getAverageUsagePerTick(), graph.getMaintenanceCost());
if (n.getBattery() == null)
sendChat(player, "gui.railcraft.charge.meter.node", avg, n.getChargeDef().getMaintenanceCost());
else {
boolean infiniteBat = n.getBattery().isInfinite();
sendChat(player, "gui.railcraft.charge.meter.producer", infiniteBat ? "INF" : n.getBattery().getCharge(), infiniteBat ? "INF" : 0.0);
}
});
returnValue = EnumActionResult.SUCCESS;
}
// }
return returnValue;
}
use of net.minecraft.util.EnumActionResult in project MinecraftForge by MinecraftForge.
the class ForgeHooks method onPlaceItemIntoWorld.
public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
// handle all placement events here
int meta = itemstack.getItemDamage();
int size = itemstack.getCount();
NBTTagCompound nbt = null;
if (itemstack.getTagCompound() != null) {
nbt = (NBTTagCompound) itemstack.getTagCompound().copy();
}
if (// if not bucket
!(itemstack.getItem() instanceof ItemBucket)) {
world.captureBlockSnapshots = true;
}
EnumActionResult ret = itemstack.getItem().onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
world.captureBlockSnapshots = false;
if (ret == EnumActionResult.SUCCESS) {
// save new item data
int newMeta = itemstack.getItemDamage();
int newSize = itemstack.getCount();
NBTTagCompound newNBT = null;
if (itemstack.getTagCompound() != null) {
newNBT = (NBTTagCompound) itemstack.getTagCompound().copy();
}
net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
@SuppressWarnings("unchecked") List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<BlockSnapshot>) world.capturedBlockSnapshots.clone();
world.capturedBlockSnapshots.clear();
// make sure to set pre-placement item data for event
itemstack.setItemDamage(meta);
itemstack.setCount(size);
if (nbt != null) {
itemstack.setTagCompound(nbt);
}
if (blockSnapshots.size() > 1) {
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand);
} else if (blockSnapshots.size() == 1) {
placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
}
if (placeEvent != null && (placeEvent.isCanceled())) {
// cancel placement
ret = EnumActionResult.FAIL;
// revert back all captured blocks
for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) {
world.restoringBlockSnapshots = true;
blocksnapshot.restore(true, false);
world.restoringBlockSnapshots = false;
}
} else {
// Change the stack to its new content
itemstack.setItemDamage(newMeta);
itemstack.setCount(newSize);
if (nbt != null) {
itemstack.setTagCompound(newNBT);
}
for (BlockSnapshot snap : blockSnapshots) {
int updateFlag = snap.getFlag();
IBlockState oldBlock = snap.getReplacedBlock();
IBlockState newBlock = world.getBlockState(snap.getPos());
if (// Containers get placed automatically
!newBlock.getBlock().hasTileEntity(newBlock)) {
newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock);
}
world.markAndNotifyBlock(snap.getPos(), null, oldBlock, newBlock, updateFlag);
}
player.addStat(StatList.getObjectUseStats(itemstack.getItem()));
}
}
world.capturedBlockSnapshots.clear();
return ret;
}
use of net.minecraft.util.EnumActionResult in project Overloaded by CJ-MC-Mods.
the class TileItemManipulator method update.
@Override
public void update() {
ItemStack currentItem = itemStack.getStackInSlot(0);
if (currentItem.isEmpty())
return;
FakePlayer player = getPlayer();
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(this.getPos());
for (int i = 0; i < player.interactionManager.getBlockReachDistance(); i++) {
if (!this.getWorld().isAirBlock(blockPos.move(this.facing))) {
EnumActionResult result = currentItem.getItem().onItemUse(player, getWorld(), blockPos, EnumHand.MAIN_HAND, facing.getOpposite(), 0.5f, 0.5f, 0.5f);
// blockPos,this.facing.getOpposite(),0.5f,0.5f,0.5f);
break;
}
}
}
use of net.minecraft.util.EnumActionResult in project Railcraft by Railcraft.
the class ItemMagnifyingGlass method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (Game.isClient(world))
return EnumActionResult.PASS;
TileEntity t = world.getTileEntity(pos);
EnumActionResult returnValue = EnumActionResult.PASS;
if (t instanceof IOwnable) {
IOwnable ownable = (IOwnable) t;
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.placedby", ownable.getDisplayName(), ownable.getOwner());
returnValue = EnumActionResult.SUCCESS;
}
if (t instanceof TileMultiBlock) {
TileMultiBlock tile = (TileMultiBlock) t;
if (tile.isStructureValid())
ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
else
for (MultiBlockStateReturn returnState : EnumSet.complementOf(EnumSet.of(MultiBlockStateReturn.VALID))) {
List<Integer> pats = tile.patternStates.get(returnState);
if (!pats.isEmpty())
ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, pats.toString());
}
returnValue = EnumActionResult.SUCCESS;
}
if (t instanceof IDualHeadSignal) {
IDualHeadSignal signal = (IDualHeadSignal) t;
SignalAspect top = signal.getSignalAspect(DualLamp.TOP);
SignalAspect bottom = signal.getSignalAspect(DualLamp.BOTTOM);
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect.dual", top.getLocalizationTag(), bottom.getLocalizationTag());
returnValue = EnumActionResult.SUCCESS;
} else if (t instanceof TileSignalBase) {
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect", ((TileSignalBase) t).getSignalAspect().getLocalizationTag());
returnValue = EnumActionResult.SUCCESS;
}
return returnValue;
}
Aggregations