use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
return false;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable cable = (TileEntityRedNetCable) te;
int subHit = getPartClicked(player, 3.0F, cable);
if (subHit < 0) {
return false;
}
side = _partSideMappings[subHit];
ItemStack s = player.inventory.getCurrentItem();
if (side >= 0) {
if (MFRUtil.isHoldingHammer(player)) {
if (!world.isRemote) {
int nextColor;
if (!player.isSneaking()) {
nextColor = cable.getSideColor(ForgeDirection.getOrientation(side)) + 1;
if (nextColor > 15)
nextColor = 0;
} else {
nextColor = cable.getSideColor(ForgeDirection.getOrientation(side)) - 1;
if (nextColor < 0)
nextColor = 15;
}
cable.setSideColor(ForgeDirection.getOrientation(side), nextColor);
world.markBlockForUpdate(x, y, z);
return true;
}
} else if (s != null && s.itemID == Item.dyePowder.itemID) {
if (!world.isRemote) {
cable.setSideColor(ForgeDirection.getOrientation(side), 15 - s.getItemDamage());
world.markBlockForUpdate(x, y, z);
return true;
}
}
} else if (MFRUtil.isHoldingHammer(player)) {
byte mode = cable.getMode();
mode++;
if (mode > 2) {
mode = 0;
}
cable.setMode(mode);
if (!world.isRemote) {
PacketDispatcher.sendPacketToAllAround(x, y, z, 50, world.provider.dimensionId, cable.getDescriptionPacket());
if (mode == 0) {
player.sendChatToPlayer("Set cable to standard connection mode");
} else if (mode == 1) {
player.sendChatToPlayer("Set cable to forced-connection mode");
} else if (mode == 2) {
player.sendChatToPlayer("Set cable to cable-only connection mode");
}
}
}
}
return false;
}
use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.
the class BlockRedNetPanel method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
return false;
}
ItemStack s = player.inventory.getCurrentItem();
TileEntity te = world.getBlockTileEntity(x, y, z);
if (MFRUtil.isHoldingHammer(player) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
((TileEntityFactory) te).rotate();
world.markBlockForUpdate(x, y, z);
return true;
} else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(player.inventory) != null) {
player.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
return true;
} else if (te instanceof TileEntityRedNetHistorian && s != null && s.itemID == Item.dyePowder.itemID) {
((TileEntityRedNetHistorian) te).setSelectedSubnet(15 - s.getItemDamage());
world.markBlockForUpdate(x, y, z);
return true;
}
return false;
}
use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float xOffset, float yOffset, float zOffset) {
PlayerInteractEvent e = new PlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
return false;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te == null) {
return false;
}
if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isEmptyContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketDrain()) {
if (MFRLiquidMover.manuallyDrainTank((ITankContainerBucketable) te, entityplayer)) {
return true;
}
} else if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isFilledContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketFill()) {
if (MFRLiquidMover.manuallyFillTank((ITankContainerBucketable) te, entityplayer)) {
return true;
}
}
if (MFRUtil.isHoldingHammer(entityplayer) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
((TileEntityFactory) te).rotate();
world.markBlockForUpdate(x, y, z);
return true;
} else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(entityplayer.inventory) != null) {
if (!world.isRemote) {
entityplayer.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
}
return true;
}
return false;
}
use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project BluePower by Qmunity.
the class TileDeployer method rightClick.
/**
* Be sure to set up the fake player's hotbar with the right clicked items. starting with hotbar slot 0.
* @param player
* @param useItems this method will set the current selected slot of the fake player to 0, and move on to the next slot useItems - 1 times.
* So to use the first slot only, pass 1, to use the full hotbar, 9.
* @return
*/
protected boolean rightClick(FakePlayer player, int useItems) {
if (useItems > 9)
throw new IllegalArgumentException("Hotbar is 9 items in width! You're trying " + useItems + "!");
ForgeDirection faceDir = getFacingDirection();
int dx = faceDir.offsetX;
int dy = faceDir.offsetY;
int dz = faceDir.offsetZ;
int x = xCoord + dx;
int y = yCoord + dy;
int z = zCoord + dz;
player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
player.rotationPitch = faceDir.offsetY * -90;
switch(faceDir) {
case NORTH:
player.rotationYaw = 180;
break;
case SOUTH:
player.rotationYaw = 0;
break;
case WEST:
player.rotationYaw = 90;
break;
case EAST:
player.rotationYaw = -90;
}
try {
PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
if (event.isCanceled())
return false;
Block block = worldObj.getBlock(x, y, z);
List<EntityLivingBase> detectedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
Entity entity = detectedEntities.isEmpty() ? null : detectedEntities.get(worldObj.rand.nextInt(detectedEntities.size()));
if (entity != null) {
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack) && stack.getItem().itemInteractionForEntity(stack, player, (EntityLivingBase) entity))
return true;
if (entity instanceof EntityAnimal && ((EntityAnimal) entity).interact(player))
return true;
}
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack) && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
if (!worldObj.isAirBlock(x, y, x) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
boolean isGoingToShift = false;
if (stack != null) {
if (stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
isGoingToShift = true;
}
}
int useX = isGoingToShift ? xCoord : x;
int useY = isGoingToShift ? yCoord : y;
int useZ = isGoingToShift ? zCoord : z;
if (canDeployItem(stack) && stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz))
return true;
}
for (int i = 0; i < useItems; i++) {
player.inventory.currentItem = i;
ItemStack stack = player.getCurrentEquippedItem();
if (canDeployItem(stack)) {
ItemStack copy = stack.copy();
player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
if (!copy.isItemEqual(stack))
return true;
}
}
return false;
} catch (Throwable e) {
BluePower.log.error("Deployer crashed! Stacktrace: ");
e.printStackTrace();
return true;
}
}
use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project LogisticsPipes by RS485.
the class LogisticsEventListener method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
if (MainProxy.isServer(event.entityPlayer.worldObj)) {
if (event.action == Action.LEFT_CLICK_BLOCK) {
final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
if (tile instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
event.setCanceled(true);
event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
} else {
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
}
}
}
}
if (event.action == Action.RIGHT_CLICK_BLOCK) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
TileEntity tileEntity = worldCoordinates.getTileEntity();
if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
//@formatter:off
List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
if (!list.isEmpty()) {
LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
}
}
}
}
}
Aggregations