use of net.minecraft.util.EnumHand in project ForestryMC by ForestryMC.
the class GuiHandler method getClientGuiElement.
@Override
@Nullable
@SideOnly(Side.CLIENT)
public Object getClientGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
GuiId guiId = decodeGuiID(guiData);
if (guiId == null) {
return null;
}
short data = decodeGuiData(guiData);
BlockPos pos = new BlockPos(x, y, z);
switch(guiId.getGuiType()) {
case Item:
{
for (EnumHand hand : EnumHand.values()) {
ItemStack heldItem = player.getHeldItem(hand);
if (!heldItem.isEmpty()) {
Item item = heldItem.getItem();
if (guiId.getGuiHandlerClass().isInstance(item)) {
return ((IGuiHandlerItem) item).getGui(player, heldItem, data);
}
}
}
break;
}
case Tile:
{
TileEntity tileEntity = TileUtil.getTile(world, pos);
if (guiId.getGuiHandlerClass().isInstance(tileEntity)) {
return ((IGuiHandlerTile) tileEntity).getGui(player, data);
}
break;
}
case Entity:
{
Entity entity = world.getEntityByID(x);
if (guiId.getGuiHandlerClass().isInstance(entity)) {
return ((IGuiHandlerEntity) entity).getGui(player, data);
}
break;
}
}
return null;
}
use of net.minecraft.util.EnumHand in project Bewitchment by Um-Mitternacht.
the class ItemVoodooPoppet method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("boundId") && stack.getTagCompound().hasKey("boundName")) {
EntityLivingBase target = world.getEntities(EntityLivingBase.class, e -> e != null && e.getPersistentID().toString().equals(stack.getTagCompound().getString("boundId"))).stream().findFirst().orElse(null);
if (target != null) {
VoodooEvent event = new VoodooEvent(player, target);
MinecraftForge.EVENT_BUS.post(event);
if (!event.isCanceled()) {
if (player.isSneaking()) {
List<ItemStack> inv = Bewitchment.proxy.getEntireInventory(player);
for (ItemStack itemStack : inv) {
if (itemStack.getItem() == ModObjects.bone_needle) {
target.attackEntityFrom(DamageSource.MAGIC, 2);
itemStack.shrink(1);
stack.damageItem(1, player);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
}
}
} else
player.sendStatusMessage(new TextComponentTranslation("poppet.protect"), true);
} else
player.sendStatusMessage(new TextComponentTranslation("poppet.not_found"), true);
}
return super.onItemRightClick(world, player, hand);
}
use of net.minecraft.util.EnumHand in project Galacticraft by micdoodle8.
the class ModelBipedGC method setRotationAngles.
public static void setRotationAngles(ModelBiped biped, float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity) {
if (!(par7Entity instanceof EntityPlayer))
return;
final EntityPlayer player = (EntityPlayer) par7Entity;
final ItemStack currentItemStack = player.inventory.getCurrentItem();
final float floatPI = 3.1415927F;
if (!par7Entity.onGround && par7Entity.world.provider instanceof IGalacticraftWorldProvider && par7Entity.getRidingEntity() == null && !(currentItemStack != null && currentItemStack.getItem() instanceof IHoldableItem)) {
float speedModifier = 0.1162F * 2;
float angularSwingArm = MathHelper.cos(par1 * (speedModifier / 2));
float rightMod = biped.rightArmPose == ModelBiped.ArmPose.ITEM ? 1 : 2;
biped.bipedRightArm.rotateAngleX -= MathHelper.cos(par1 * 0.6662F + floatPI) * rightMod * par2 * 0.5F;
biped.bipedLeftArm.rotateAngleX -= MathHelper.cos(par1 * 0.6662F) * 2.0F * par2 * 0.5F;
biped.bipedRightArm.rotateAngleX += -angularSwingArm * 4.0F * par2 * 0.5F;
biped.bipedLeftArm.rotateAngleX += angularSwingArm * 4.0F * par2 * 0.5F;
biped.bipedLeftLeg.rotateAngleX -= MathHelper.cos(par1 * 0.6662F + floatPI) * 1.4F * par2;
biped.bipedLeftLeg.rotateAngleX += MathHelper.cos(par1 * 0.1162F * 2 + floatPI) * 1.4F * par2;
biped.bipedRightLeg.rotateAngleX -= MathHelper.cos(par1 * 0.6662F) * 1.4F * par2;
biped.bipedRightLeg.rotateAngleX += MathHelper.cos(par1 * 0.1162F * 2) * 1.4F * par2;
}
PlayerGearData gearData = GalacticraftCore.proxy.getGearData(player);
if (gearData != null) {
if (gearData.getParachute() != null) {
// Parachute is equipped
biped.bipedLeftArm.rotateAngleX += floatPI;
biped.bipedLeftArm.rotateAngleZ += floatPI / 10;
biped.bipedRightArm.rotateAngleX += floatPI;
biped.bipedRightArm.rotateAngleZ -= floatPI / 10;
}
}
ItemStack heldItemStack = null;
for (EnumHand hand : EnumHand.values()) {
ItemStack item = player.getHeldItem(hand);
if (item != null && item.getItem() instanceof IHoldableItem) {
heldItemStack = item;
}
}
if (heldItemStack != null && !(player.getRidingEntity() instanceof ICameraZoomEntity)) {
Item heldItem = heldItemStack.getItem();
IHoldableItem holdableItem = (IHoldableItem) heldItem;
IHoldableItemCustom holdableItemCustom = heldItem instanceof IHoldableItemCustom ? (IHoldableItemCustom) heldItem : null;
if (holdableItem.shouldHoldLeftHandUp(player)) {
Vector3 angle = null;
if (holdableItemCustom != null) {
angle = holdableItemCustom.getLeftHandRotation(player);
}
if (angle == null) {
angle = new Vector3(floatPI + 0.3F, 0.0F, floatPI / 10.0F);
}
biped.bipedLeftArm.rotateAngleX = angle.floatX();
biped.bipedLeftArm.rotateAngleY = angle.floatY();
biped.bipedLeftArm.rotateAngleZ = angle.floatZ();
}
if (holdableItem.shouldHoldRightHandUp(player)) {
Vector3 angle = null;
if (holdableItemCustom != null) {
angle = holdableItemCustom.getRightHandRotation(player);
}
if (angle == null) {
angle = new Vector3(floatPI + 0.3F, 0.0F, (float) -Math.PI / 10.0F);
}
biped.bipedRightArm.rotateAngleX = angle.floatX();
biped.bipedRightArm.rotateAngleY = angle.floatY();
biped.bipedRightArm.rotateAngleZ = angle.floatZ();
}
}
for (Entity e : player.world.loadedEntityList) {
if (e instanceof EntityTieredRocket && e.getDistanceSq(player) < 200) {
final EntityTieredRocket ship = (EntityTieredRocket) e;
if (!ship.getPassengers().isEmpty() && !ship.getPassengers().contains(player) && (ship.getLaunched() || ship.timeUntilLaunch < 390)) {
biped.bipedRightArm.rotateAngleZ -= floatPI / 8F + MathHelper.sin(par3 * 0.9F) * 0.2F;
biped.bipedRightArm.rotateAngleX = floatPI;
break;
}
}
}
if (player.isPlayerSleeping() && GalacticraftCore.isPlanetsLoaded) {
RenderPlayerGC.RotatePlayerEvent event = new RenderPlayerGC.RotatePlayerEvent((AbstractClientPlayer) player);
MinecraftForge.EVENT_BUS.post(event);
if (event.vanillaOverride && (event.shouldRotate == null || event.shouldRotate)) {
biped.bipedHead.rotateAngleX = (float) (20.0F - Math.sin(player.ticksExisted / 10.0F) / 7.0F);
biped.bipedHead.rotateAngleY = 0.0F;
biped.bipedHead.rotateAngleZ = 0.0F;
biped.bipedLeftArm.rotateAngleX = 0.0F;
biped.bipedLeftArm.rotateAngleY = 0.0F;
biped.bipedLeftArm.rotateAngleZ = 0.0F;
biped.bipedRightArm.rotateAngleX = 0.0F;
biped.bipedRightArm.rotateAngleY = 0.0F;
biped.bipedRightArm.rotateAngleZ = 0.0F;
}
}
ModelBiped.copyModelAngles(biped.bipedHead, biped.bipedHeadwear);
}
use of net.minecraft.util.EnumHand in project Galacticraft by micdoodle8.
the class PacketSimple method handleServerSide.
@Override
public void handleServerSide(EntityPlayer player) {
final EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
if (playerBase == null) {
return;
}
final MinecraftServer server = playerBase.mcServer;
final GCPlayerStats stats = GCPlayerStats.get(playerBase);
switch(this.type) {
case S_RESPAWN_PLAYER:
playerBase.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), playerBase.interactionManager.getGameType()));
break;
case S_TELEPORT_ENTITY:
TickHandlerServer.scheduleNewDimensionChange(new ScheduledDimensionChange(playerBase, (int) PacketSimple.this.data.get(0)));
break;
case S_IGNITE_ROCKET:
if (!player.world.isRemote && !player.isDead && player.getRidingEntity() != null && !player.getRidingEntity().isDead && player.getRidingEntity() instanceof EntityTieredRocket) {
final EntityTieredRocket ship = (EntityTieredRocket) player.getRidingEntity();
if (ship.launchPhase != EnumLaunchPhase.LANDING.ordinal()) {
if (ship.hasValidFuel()) {
ItemStack stack2 = stats.getExtendedInventory().getStackInSlot(4);
if (stack2 != null && stack2.getItem() instanceof ItemParaChute || stats.getLaunchAttempts() > 0) {
ship.igniteCheckingCooldown();
stats.setLaunchAttempts(0);
} else if (stats.getChatCooldown() == 0 && stats.getLaunchAttempts() == 0) {
player.sendMessage(new TextComponentString(GCCoreUtil.translate("gui.rocket.warning.noparachute")));
stats.setChatCooldown(80);
stats.setLaunchAttempts(1);
}
} else if (stats.getChatCooldown() == 0) {
player.sendMessage(new TextComponentString(GCCoreUtil.translate("gui.rocket.warning.nofuel")));
stats.setChatCooldown(250);
}
}
}
break;
case S_OPEN_SCHEMATIC_PAGE:
if (player != null) {
final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));
player.openGui(GalacticraftCore.instance, page.getGuiID(), player.world, (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));
}
break;
case S_OPEN_FUEL_GUI:
if (player.getRidingEntity() instanceof EntityBuggy) {
GCCoreUtil.openBuggyInv(playerBase, (EntityBuggy) player.getRidingEntity(), ((EntityBuggy) player.getRidingEntity()).getType());
} else if (player.getRidingEntity() instanceof EntitySpaceshipBase) {
player.openGui(GalacticraftCore.instance, GuiIdsCore.ROCKET_INVENTORY, player.world, (int) player.posX, (int) player.posY, (int) player.posZ);
}
break;
case S_UPDATE_SHIP_YAW:
if (player.getRidingEntity() instanceof EntitySpaceshipBase) {
final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.getRidingEntity();
if (ship != null) {
ship.rotationYaw = (Float) this.data.get(0);
}
}
break;
case S_UPDATE_SHIP_PITCH:
if (player.getRidingEntity() instanceof EntitySpaceshipBase) {
final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.getRidingEntity();
if (ship != null) {
ship.rotationPitch = (Float) this.data.get(0);
}
}
break;
case S_SET_ENTITY_FIRE:
Entity entity = player.world.getEntityByID((Integer) this.data.get(0));
if (entity instanceof EntityLivingBase) {
((EntityLivingBase) entity).setFire(3);
}
break;
case S_BIND_SPACE_STATION_ID:
int homeID = (Integer) this.data.get(0);
if ((!stats.getSpaceStationDimensionData().containsKey(homeID) || stats.getSpaceStationDimensionData().get(homeID) == -1 || stats.getSpaceStationDimensionData().get(homeID) == 0) && !ConfigManagerCore.disableSpaceStationCreation) {
if (playerBase.capabilities.isCreativeMode || WorldUtil.getSpaceStationRecipe(homeID).matches(playerBase, true)) {
GCTriggers.CREATE_SPACE_STATION.trigger(playerBase);
WorldUtil.bindSpaceStationToNewDimension(playerBase.world, playerBase, homeID);
}
}
break;
case S_UNLOCK_NEW_SCHEMATIC:
final Container container = player.openContainer;
if (container instanceof ContainerSchematic) {
final ContainerSchematic schematicContainer = (ContainerSchematic) container;
ItemStack stack = schematicContainer.craftMatrix.getStackInSlot(0);
if (!stack.isEmpty()) {
final ISchematicPage page = SchematicRegistry.getMatchingRecipeForItemStack(stack);
if (page != null) {
SchematicRegistry.unlockNewPage(playerBase, stack);
SpaceRaceManager.teamUnlockSchematic(playerBase, stack);
stack.shrink(1);
schematicContainer.craftMatrix.setInventorySlotContents(0, stack);
schematicContainer.craftMatrix.markDirty();
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_ADD_NEW_SCHEMATIC, getDimensionID(), new Object[] { page.getPageID() }), playerBase);
}
}
}
break;
case S_UPDATE_DISABLEABLE_BUTTON:
final TileEntity tileAt = player.world.getTileEntity((BlockPos) this.data.get(0));
if (tileAt instanceof IDisableableMachine) {
final IDisableableMachine machine = (IDisableableMachine) tileAt;
machine.setDisabled((Integer) this.data.get(1), !machine.getDisabled((Integer) this.data.get(1)));
}
break;
case S_ON_FAILED_CHEST_UNLOCK:
if (stats.getChatCooldown() == 0) {
player.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.chest.warning.wrongkey", this.data.get(0))));
stats.setChatCooldown(100);
}
break;
case S_RENAME_SPACE_STATION:
final SpaceStationWorldData ssdata = SpaceStationWorldData.getStationData(playerBase.world, (Integer) this.data.get(1), playerBase);
if (ssdata != null && ssdata.getOwner().equalsIgnoreCase(PlayerUtil.getName(player))) {
ssdata.setSpaceStationName((String) this.data.get(0));
ssdata.setDirty(true);
}
break;
case S_OPEN_EXTENDED_INVENTORY:
player.openGui(GalacticraftCore.instance, GuiIdsCore.EXTENDED_INVENTORY, player.world, 0, 0, 0);
break;
case S_ON_ADVANCED_GUI_CLICKED_INT:
TileEntity tile1 = player.world.getTileEntity((BlockPos) this.data.get(1));
switch((Integer) this.data.get(0)) {
case 0:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.redstoneActivation = (Integer) this.data.get(2) == 1;
}
break;
case 1:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.playerDistanceActivation = (Integer) this.data.get(2) == 1;
}
break;
case 2:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.playerDistanceSelection = (Integer) this.data.get(2);
}
break;
case 3:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.playerNameMatches = (Integer) this.data.get(2) == 1;
}
break;
case 4:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.invertSelection = (Integer) this.data.get(2) == 1;
}
break;
case 5:
if (tile1 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
airlockController.lastHorizontalModeEnabled = airlockController.horizontalModeEnabled;
airlockController.horizontalModeEnabled = (Integer) this.data.get(2) == 1;
}
break;
case 6:
if (tile1 instanceof IBubbleProvider) {
IBubbleProvider distributor = (IBubbleProvider) tile1;
distributor.setBubbleVisible((Integer) this.data.get(2) == 1);
}
break;
default:
break;
}
break;
case S_ON_ADVANCED_GUI_CLICKED_STRING:
TileEntity tile2 = player.world.getTileEntity((BlockPos) this.data.get(1));
switch((Integer) this.data.get(0)) {
case 0:
if (tile2 instanceof TileEntityAirLockController) {
TileEntityAirLockController airlockController = (TileEntityAirLockController) tile2;
airlockController.playerToOpenFor = (String) this.data.get(2);
}
break;
default:
break;
}
break;
case S_UPDATE_SHIP_MOTION_Y:
int entityID = (Integer) this.data.get(0);
boolean up = (Boolean) this.data.get(1);
Entity entity2 = player.world.getEntityByID(entityID);
if (entity2 instanceof EntityAutoRocket) {
EntityAutoRocket autoRocket = (EntityAutoRocket) entity2;
autoRocket.motionY += up ? 0.02F : -0.02F;
}
break;
case S_START_NEW_SPACE_RACE:
Integer teamID = (Integer) this.data.get(0);
String teamName = (String) this.data.get(1);
FlagData flagData = (FlagData) this.data.get(2);
Vector3 teamColor = (Vector3) this.data.get(3);
List<String> playerList = new ArrayList<String>();
for (int i = 4; i < this.data.size(); i++) {
playerList.add((String) this.data.get(i));
}
boolean previousData = SpaceRaceManager.getSpaceRaceFromID(teamID) != null;
SpaceRace newRace = new SpaceRace(playerList, teamName, flagData, teamColor);
if (teamID > 0) {
newRace.setSpaceRaceID(teamID);
}
SpaceRaceManager.addSpaceRace(newRace);
if (previousData) {
SpaceRaceManager.sendSpaceRaceData(server, null, SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(playerBase)));
}
break;
case S_REQUEST_FLAG_DATA:
SpaceRaceManager.sendSpaceRaceData(server, playerBase, SpaceRaceManager.getSpaceRaceFromPlayer((String) this.data.get(0)));
break;
case S_INVITE_RACE_PLAYER:
EntityPlayerMP playerInvited = PlayerUtil.getPlayerBaseServerFromPlayerUsername(server, (String) this.data.get(0), true);
if (playerInvited != null) {
Integer teamInvitedTo = (Integer) this.data.get(1);
SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);
if (race != null) {
GCPlayerStats.get(playerInvited).setSpaceRaceInviteTeamID(teamInvitedTo);
String dA = EnumColor.DARK_AQUA.getCode();
String bG = EnumColor.BRIGHT_GREEN.getCode();
String dB = EnumColor.PURPLE.getCode();
String teamNameTotal = "";
String[] teamNameSplit = race.getTeamName().split(" ");
for (String teamNamePart : teamNameSplit) {
teamNameTotal = teamNameTotal.concat(dB + teamNamePart + " ");
}
playerInvited.sendMessage(new TextComponentString(dA + GCCoreUtil.translateWithFormat("gui.space_race.chat.invite_received", bG + PlayerUtil.getName(player) + dA) + " " + GCCoreUtil.translateWithFormat("gui.space_race.chat.to_join", teamNameTotal, EnumColor.AQUA + "/joinrace" + dA)).setStyle(new Style().setColor(TextFormatting.DARK_AQUA)));
}
}
break;
case S_REMOVE_RACE_PLAYER:
Integer teamInvitedTo = (Integer) this.data.get(1);
SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);
if (race != null) {
String playerToRemove = (String) this.data.get(0);
if (!race.getPlayerNames().remove(playerToRemove)) {
player.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.space_race.chat.not_found", playerToRemove)));
} else {
SpaceRaceManager.onPlayerRemoval(server, playerToRemove, race);
}
}
break;
case S_ADD_RACE_PLAYER:
Integer teamToAddPlayer = (Integer) this.data.get(1);
SpaceRace spaceRaceToAddPlayer = SpaceRaceManager.getSpaceRaceFromID(teamToAddPlayer);
if (spaceRaceToAddPlayer != null) {
String playerToAdd = (String) this.data.get(0);
if (!spaceRaceToAddPlayer.getPlayerNames().contains(playerToAdd)) {
SpaceRace oldRace = null;
while ((oldRace = SpaceRaceManager.getSpaceRaceFromPlayer(playerToAdd)) != null) {
SpaceRaceManager.removeSpaceRace(oldRace);
}
spaceRaceToAddPlayer.getPlayerNames().add(playerToAdd);
SpaceRaceManager.sendSpaceRaceData(server, null, spaceRaceToAddPlayer);
for (String member : spaceRaceToAddPlayer.getPlayerNames()) {
EntityPlayerMP memberObj = PlayerUtil.getPlayerForUsernameVanilla(server, member);
if (memberObj != null) {
memberObj.sendMessage(new TextComponentString(EnumColor.DARK_AQUA + GCCoreUtil.translateWithFormat("gui.space_race.chat.add_success", EnumColor.BRIGHT_GREEN + playerToAdd + EnumColor.DARK_AQUA)).setStyle(new Style().setColor(TextFormatting.DARK_AQUA)));
}
}
} else {
player.sendMessage(new TextComponentString(GCCoreUtil.translate("gui.space_race.chat.already_part")).setStyle(new Style().setColor(TextFormatting.DARK_RED)));
}
}
break;
case S_COMPLETE_CBODY_HANDSHAKE:
String completeList = (String) this.data.get(0);
List<String> clientObjects = Arrays.asList(completeList.split(";"));
List<String> serverObjects = Lists.newArrayList();
String missingObjects = "";
for (CelestialBody cBody : GalaxyRegistry.getRegisteredPlanets().values()) {
serverObjects.add(cBody.getUnlocalizedName());
}
for (CelestialBody cBody : GalaxyRegistry.getRegisteredMoons().values()) {
serverObjects.add(cBody.getUnlocalizedName());
}
for (CelestialBody cBody : GalaxyRegistry.getRegisteredSatellites().values()) {
serverObjects.add(cBody.getUnlocalizedName());
}
for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
serverObjects.add(solarSystem.getUnlocalizedName());
}
for (String str : serverObjects) {
if (!clientObjects.contains(str)) {
missingObjects = missingObjects.concat(str + "\n");
}
}
if (missingObjects.length() > 0) {
playerBase.connection.disconnect(new TextComponentString("Missing Galacticraft Celestial Objects:\n\n " + missingObjects));
}
break;
case S_REQUEST_GEAR_DATA1:
case S_REQUEST_GEAR_DATA2:
UUID id = (UUID) this.data.get(0);
if (id != null) {
EntityPlayer otherPlayer = player.world.getPlayerEntityByUUID(id);
if (otherPlayer instanceof EntityPlayerMP) {
GCPlayerHandler.checkGear((EntityPlayerMP) otherPlayer, GCPlayerStats.get(otherPlayer), true);
}
}
break;
case S_BUILDFLAGS_UPDATE:
stats.setBuildFlags((Integer) this.data.get(0));
break;
case S_REQUEST_OVERWORLD_IMAGE:
MapUtil.sendOverworldToClient(playerBase);
break;
case S_REQUEST_MAP_IMAGE:
int dim = (Integer) this.data.get(0);
int cx = (Integer) this.data.get(1);
int cz = (Integer) this.data.get(2);
MapUtil.sendOrCreateMap(WorldUtil.getProviderForDimensionServer(dim).world, cx, cz, playerBase);
break;
case S_REQUEST_PLAYERSKIN:
String strName = (String) this.data.get(0);
EntityPlayerMP playerRequested = server.getPlayerList().getPlayerByUsername(strName);
// Player not online
if (playerRequested == null) {
return;
}
GameProfile gp = playerRequested.getGameProfile();
if (gp == null) {
return;
}
Property property = (Property) Iterables.getFirst(gp.getProperties().get("textures"), (Object) null);
if (property == null) {
return;
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_SEND_PLAYERSKIN, getDimensionID(), new Object[] { strName, property.getValue(), property.getSignature(), playerRequested.getUniqueID().toString() }), playerBase);
break;
case S_CONTROL_ENTITY:
if (player.getRidingEntity() != null && player.getRidingEntity() instanceof IControllableEntity) {
((IControllableEntity) player.getRidingEntity()).pressKey((Integer) this.data.get(0));
}
break;
case S_NOCLIP_PLAYER:
boolean noClip = (Boolean) this.data.get(0);
if (player instanceof GCEntityPlayerMP) {
GalacticraftCore.proxy.player.setNoClip((EntityPlayerMP) player, noClip);
if (noClip == false) {
player.fallDistance = 0.0F;
((EntityPlayerMP) player).connection.floatingTickCount = 0;
}
} else if (player instanceof EntityPlayerMP) {
EntityPlayerMP emp = ((EntityPlayerMP) player);
try {
Field f = emp.interactionManager.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "gameType" : "field_73091_c");
f.setAccessible(true);
if (noClip == false) {
emp.fallDistance = 0.0F;
emp.connection.floatingTickCount = 0;
GameType gt = savedSettings.get(emp);
if (gt != null) {
savedSettings.remove(emp);
f.set(emp.interactionManager, gt);
}
} else {
savedSettings.put(emp, emp.interactionManager.getGameType());
f.set(emp.interactionManager, GameType.SPECTATOR);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
break;
case S_REQUEST_DATA:
WorldServer worldServer = server.getWorld((Integer) this.data.get(0));
if (worldServer != null) {
TileEntity requestedTile = worldServer.getTileEntity((BlockPos) this.data.get(1));
if (requestedTile instanceof INetworkProvider) {
if (((INetworkProvider) requestedTile).getNetwork() instanceof FluidNetwork) {
FluidNetwork network = (FluidNetwork) ((INetworkProvider) requestedTile).getNetwork();
network.addUpdate(playerBase);
}
}
}
break;
case S_UPDATE_CHECKLIST:
for (EnumHand enumhand : EnumHand.values()) {
ItemStack stack = player.getHeldItem(enumhand);
if (stack != null && stack.getItem() == GCItems.prelaunchChecklist) {
NBTTagCompound tagCompound = stack.getTagCompound();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound tagCompoundRead = (NBTTagCompound) this.data.get(0);
tagCompound.setTag("checklistData", tagCompoundRead);
stack.setTagCompound(tagCompound);
}
}
break;
case S_REQUEST_MACHINE_DATA:
TileEntity tile3 = player.world.getTileEntity((BlockPos) this.data.get(0));
if (tile3 instanceof ITileClientUpdates) {
((ITileClientUpdates) tile3).sendUpdateToClient(playerBase);
}
break;
case S_REQUEST_CONTAINER_SLOT_REFRESH:
// server -> client
if (player.openContainer.windowId == (Integer) this.data.get(0)) {
for (int i = 0; i < player.openContainer.inventoryItemStacks.size(); ++i) {
player.openContainer.inventoryItemStacks.set(i, ItemStack.EMPTY);
}
}
break;
default:
break;
}
}
use of net.minecraft.util.EnumHand in project ModJam-5 by strikerrocker.
the class CommonEvents method onRightClickEntity.
@SubscribeEvent
public static void onRightClickEntity(PlayerInteractEvent.EntityInteract event) {
if (event.getTarget() instanceof EntityVillager && event.getEntity() instanceof EntityPlayer && !event.getWorld().isRemote) {
EntityVillager villager = (EntityVillager) event.getTarget();
EntityPlayer player = (EntityPlayer) event.getEntity();
EnumHand hand = player.getActiveHand();
if (villager.getLeashed() && villager.getLeashHolder() == player) {
villager.clearLeashed(true, !player.capabilities.isCreativeMode);
event.setCanceled(true);
return;
} else {
ItemStack itemstack = player.getHeldItem(hand);
if (itemstack.getItem() == Items.LEAD) {
villager.setLeashHolder(player, true);
if (!player.isCreative())
itemstack.shrink(1);
event.setCanceled(true);
return;
}
}
}
}
Aggregations