use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class GuiPlugin method onSeedAnalyzerRightClick.
public void onSeedAnalyzerRightClick(PlayerInteractEvent.RightClickBlock event) {
BlockPos pos = event.getPos();
BlockState state = event.getWorld().getBlockState(pos);
if (event.getPlayer().isSneaking()) {
return;
}
if (state.getBlock() != AgriCraft.instance.getModBlockRegistry().seed_analyzer.getBlock()) {
return;
}
event.setCancellationResult(ActionResultType.SUCCESS);
event.setCanceled(true);
if (event.getPlayer().world.isRemote) {
return;
}
INamedContainerProvider containerProvider = new INamedContainerProvider() {
@Nonnull
@Override
public ITextComponent getDisplayName() {
return new TranslationTextComponent("screen.agricraft.seed_analyzer");
}
@Override
public Container createMenu(int id, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity player) {
return new SeedAnalyzerContainer(id, event.getWorld(), playerInventory, pos);
}
};
NetworkHooks.openGui((ServerPlayerEntity) event.getPlayer(), containerProvider, pos);
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class ItemDynamicAgriSeed method onItemUse.
@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos();
TileEntity tile = world.getTileEntity(pos);
ItemStack stack = context.getItem();
PlayerEntity player = context.getPlayer();
// If crop sticks were clicked, attempt to plant the seed
if (tile instanceof TileEntityCropSticks) {
return this.attemptSeedPlant((TileEntityCropSticks) tile, stack, player);
}
// If a soil was clicked, check the block on top of the soil and handle accordingly
return AgriApi.getSoil(world, pos).map(soil -> {
BlockPos up = pos.up();
TileEntity above = world.getTileEntity(up);
// There are currently crop sticks on the soil, attempt to plant on the crop sticks
if (above instanceof TileEntityCropSticks) {
return this.attemptSeedPlant((TileEntityCropSticks) above, stack, player);
}
// There are currently no crop sticks, check if the place is suitable and plant the plant directly
if (above == null && AgriCraft.instance.getConfig().allowPlantingOutsideCropSticks()) {
BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, up);
if (newState != null && world.setBlockState(up, newState, 11)) {
boolean success = AgriApi.getCrop(world, up).map(crop -> this.getGenome(context.getItem()).map(genome -> crop.plantGenome(genome, player)).map(result -> {
if (result) {
// consume item
if (player == null || !player.isCreative()) {
stack.shrink(1);
}
}
return result;
}).orElse(false)).orElse(false);
if (success) {
return ActionResultType.SUCCESS;
} else {
world.setBlockState(up, Blocks.AIR.getDefaultState());
}
}
}
// Neither alternative option was successful, delegate the call to the super method
return super.onItemUse(context);
}).orElse(super.onItemUse(context));
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class BlockGreenHouseAirRenderer method render.
@SubscribeEvent
@SuppressWarnings("unused")
public void render(RenderWorldLastEvent event) {
PlayerEntity player = AgriCraft.instance.getClientPlayer();
ItemStack stack = player.getHeldItemMainhand();
if (stack.getItem() != AgriCraft.instance.getModItemRegistry().debugger) {
return;
}
if (AgriCraft.instance.getModItemRegistry().debugger.getDebugMode(stack) instanceof DebugModeGreenHouse) {
this.highlightGreenHouseAirBlocks(player.getEntityWorld(), player.getPosition(), event.getMatrixStack());
}
}
use of net.minecraft.entity.player.PlayerEntity in project Geolosys by oitsjustjose.
the class ManualGifting method onPlayerJoin.
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (!CommonConfig.GIVE_MANUAL_TO_NEW.get()) {
return;
}
PlayerEntity player = event.getPlayer();
IDepositCapability geolosysCap = event.getEntity().getEntityWorld().getCapability(GeolosysAPI.GEOLOSYS_WORLD_CAPABILITY).orElse(null);
if (geolosysCap == null) {
return;
}
if (!geolosysCap.hasPlayerReceivedManual(player.getUniqueID())) {
ItemHandlerHelper.giveItemToPlayer(player, PatchouliAPI.get().getBookStack(new ResourceLocation(Constants.MODID, "field_manual")));
geolosysCap.setPlayerReceivedManual(player.getUniqueID());
}
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class PlayerAngleLocker method storePlayerAngles.
public static void storePlayerAngles() {
PlayerEntity player = AgriCraft.instance.getClientPlayer();
yaw = player.rotationYaw;
yawCamera = player.cameraYaw;
yawOffset = player.renderYawOffset;
yawHead = player.rotationYawHead;
pitch = player.rotationPitch;
}
Aggregations