use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.
the class PlayerInterfaceRenderer method render.
@Override
public void render(@Nonnull TilePlayerInterface te, float v, @Nonnull MatrixStack matrixStack, @Nonnull IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
UUID uuid = te.getPlacer();
if (uuid == null)
return;
PlayerEntity player = te.getLevel().getPlayerByUUID(uuid);
if (player == null) {
if (!uuid.equals(uuidCache)) {
uuidCache = uuid;
CompoundNBT tag = new CompoundNBT();
tag.putString("SkullOwner", uuid.toString());
stackCache = new ItemStack(Items.PLAYER_HEAD, 1, tag);
}
renderItem(te, stackCache, matrixStack, iRenderTypeBuffer);
return;
}
renderPlayer(te, player, matrixStack, iRenderTypeBuffer, combinedLightIn);
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class DebugModeIGrowable method debugActionBlockClicked.
@Override
public void debugActionBlockClicked(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote) {
return;
}
BlockPos pos = context.getPos();
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
// Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :(
StringBuilder outputRaw = new StringBuilder(String.format("`7%1$4d,%2$4d,%3$4d`r ", pos.getX(), pos.getY(), pos.getZ()));
// Check if the clicked on block has the IGrowable interface.
final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null);
if (crop == null) {
// If it does not, add a nicely formatted report, then skip onward.
outputRaw.append(chatNotIG);
} else if (world instanceof ServerWorld) {
// Otherwise run the tests and record the results.
BlockState state = world.getBlockState(pos);
// canGrow
outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse);
// canUseBonemeal
outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse);
// grow
crop.grow((ServerWorld) world, world.rand, pos, state);
// It's also helpful to also make clear what block was being tested.
// '3' is dark aqua.
outputRaw.append("`3");
outputRaw.append(crop.toString().replaceFirst("Block", ""));
outputRaw.append("`r");
}
// Ellipsis are added as a clue that there's more text.
// '8' is dark gray.
outputRaw.append(" `8[...]`r");
// Create a hover box with explanatory information.
StringTextComponent hoverComponent = new StringTextComponent(MessageUtil.colorize(chatInfo));
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent);
// Turn the output String into a chat message.
StringTextComponent outputComponent = new StringTextComponent(MessageUtil.colorize(outputRaw.toString()));
// Add the hover box to the chat message.
outputComponent.getStyle().setHoverEvent(hoverEvent);
// Now send the completed chat message.
player.sendMessage(outputComponent, Util.DUMMY_UUID);
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class ItemClipper method onItemUse.
@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
World world = context.getWorld();
if (world.isRemote()) {
return ActionResultType.PASS;
}
BlockPos pos = context.getPos();
ItemStack stack = context.getItem();
PlayerEntity player = context.getPlayer();
return AgriApi.getCrop(world, pos).map(crop -> {
if (!crop.hasPlant() || !crop.getPlant().allowsClipping(crop.getGrowthStage(), stack, player)) {
if (player != null) {
player.sendMessage(AgriToolTips.MSG_CLIPPING_IMPOSSIBLE, player.getUniqueID());
}
return ActionResultType.FAIL;
}
if (MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Clip.Pre(crop, stack, player))) {
return ActionResultType.FAIL;
}
List<ItemStack> drops = Lists.newArrayList();
crop.getPlant().getClipProducts(drops::add, stack, crop.getGrowthStage(), crop.getStats(), world.getRandom());
crop.setGrowthStage(crop.getPlant().getInitialGrowthStage());
crop.getPlant().onClipped(crop, stack, player);
AgriCropEvent.Clip.Post event = new AgriCropEvent.Clip.Post(crop, stack, drops, player);
MinecraftForge.EVENT_BUS.post(event);
event.getDrops().forEach(crop::dropItem);
return ActionResultType.SUCCESS;
}).orElse(ActionResultType.FAIL);
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class ItemTrowel method tryNewPlant.
protected ActionResultType tryNewPlant(World world, BlockPos pos, ItemStack stack, @Nullable PlayerEntity player) {
if (AgriCraft.instance.getConfig().allowPlantingOutsideCropSticks()) {
BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
if (newState != null && world.setBlockState(pos, newState, 11)) {
boolean success = AgriApi.getCrop(world, pos).map(crop -> {
if (MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Trowel.Pre(crop, stack, player))) {
return false;
}
return this.getGenome(stack).map(genome -> this.getGrowthStage(stack).map(stage -> {
boolean result = crop.plantGenome(genome, player) && this.setGrowthStage(crop, stage);
if (result) {
this.removePlant(stack);
MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Trowel.Post(crop, stack, player));
}
return result;
}).orElse(false)).orElse(false);
}).orElse(false);
if (success) {
return ActionResultType.SUCCESS;
} else {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}
return ActionResultType.FAIL;
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class JeiPlugin method onRuntimeAvailable.
@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
jei = jeiRuntime;
if (AgriCraft.instance.getConfig().progressiveJEI()) {
PlayerEntity player = AgriCraft.instance.getClientPlayer();
AgriApi.getMutationRegistry().stream().forEach(mutation -> {
if (CapabilityResearchedPlants.getInstance().isMutationResearched(player, mutation)) {
unHideMutation(mutation);
} else {
hideMutation(mutation);
}
});
}
}
Aggregations