use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class AgriWailaCropBlockInfoProvider method appendBody.
@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
AgriApi.getCrop(accessor.getWorld(), accessor.getPosition()).ifPresent(crop -> {
PlayerEntity player = accessor.getPlayer();
// Add data including full genome if in creative mode
if (player.getHeldItemMainhand().getItem() == AgriCraft.instance.getModItemRegistry().debugger) {
crop.addDisplayInfo(tooltip::add);
tooltip.add(AgriToolTips.GENOME);
crop.getGenome().map(genome -> {
genome.addDisplayInfo(tooltip::add);
return true;
}).orElseGet(() -> {
tooltip.add(AgriToolTips.UNKNOWN);
return false;
});
} else {
// add crop data
if (this.shouldAddInfo(player)) {
crop.addDisplayInfo(tooltip::add);
}
}
});
AgriApi.getSoil(accessor.getWorld(), accessor.getPosition()).ifPresent(soil -> soil.addDisplayInfo(tooltip::add));
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class MagnifyingGlassViewHandler method onPlayerTick.
@SuppressWarnings("unused")
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
this.animationCounterPrev = this.animationCounter;
if (this.isActive()) {
// Check if the player is still holding the item and if not, deactivate
if (this.getActiveHand() == null || !(this.getPlayer().getHeldItem(this.getActiveHand()).getItem() instanceof ItemMagnifyingGlass)) {
this.active = false;
this.endInspection();
return;
}
// Increment animation counter
if (this.animationCounter < ANIMATION_DURATION) {
this.animationCounter += 1;
} else {
this.animationCounter = ANIMATION_DURATION;
}
if (this.isAnimationComplete()) {
// Update inspected position
this.checkInspectedPosition();
// Tick inspector
if (this.inspector != null && this.lastTarget != null) {
World world = AgriCraft.instance.getClientWorld();
PlayerEntity player = AgriCraft.instance.getClientPlayer();
if (!this.lastTarget.onInspectionTick(world, this.inspector, player)) {
this.endInspection();
}
}
}
} else {
// Decrement animation counter
if (this.animationCounter > 0) {
this.animationCounter -= 1;
} else {
this.animationCounter = 0;
this.hand = null;
}
}
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class VanillaSeedConversionHandler method runPlantingConversion.
protected boolean runPlantingConversion(World world, BlockPos pos, ItemStack stack, PlayerEntity player, Hand hand) {
return !AgriCraft.instance.getConfig().convertSeedsOnlyInAnalyzer() && AgriApi.getGenomeAdapterizer().valueOf(stack).map(seed -> {
// The player is attempting to plant a seed, convert it to an agricraft crop
return AgriApi.getSoil(world, pos.down()).map(soil -> {
// check if there are crop sticks above
MutableBoolean consumed = new MutableBoolean(false);
boolean cropSticks = AgriApi.getCrop(world, pos).map(crop -> {
if (!crop.hasPlant() && !crop.isCrossCrop() && crop.plantGenome(seed, player)) {
if (player == null || !player.isCreative()) {
stack.shrink(1);
consumed.setValue(true);
}
if (player != null) {
player.swingArm(hand);
}
}
return true;
}).orElse(false);
// if there were crop sticks, return the result of the crop sticks action
if (cropSticks) {
return consumed.getValue();
}
// no crop sticks, try planting as a plant
BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
if (newState != null && world.setBlockState(pos, newState, 11)) {
boolean planted = AgriApi.getCrop(world, pos).map(crop -> crop.plantGenome(seed, player)).orElse(false);
if (planted) {
// reduce stack size
if (player == null || !player.isCreative()) {
stack.shrink(1);
}
// return success
return true;
} else {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
return false;
}).orElse(false);
}).orElse(false);
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class JsonFertilizer method applyFertilizer.
@Override
public ActionResultType applyFertilizer(World world, BlockPos pos, IAgriFertilizable target, ItemStack stack, Random random, @Nullable LivingEntity entity) {
if (target instanceof IAgriPlantProvider) {
IAgriCrop crop = ((IAgriCrop) target);
String type = "neutral";
for (int i = 0; i < this.potency; i++) {
if (fertilizerEffect.isNegativelyAffected(crop.getPlant().getId())) {
if (fertilizerEffect.canReduceGrowth() && random.nextBoolean()) {
type = "negative";
IAgriGrowthStage current = crop.getGrowthStage();
IAgriGrowthStage previous = current.getPreviousStage(crop, random);
if (current.equals(previous)) {
if (fertilizerEffect.canKillPlant()) {
crop.removeGenome();
}
} else {
crop.setGrowthStage(previous);
}
}
} else {
if (crop.hasPlant() && this.fertilizerEffect.canFertilize(crop.getPlant().getId())) {
target.applyGrowthTick();
type = "positive";
} else if (crop.isCrossCrop() && this.canTriggerMutation()) {
target.applyGrowthTick();
type = "positive";
} else if (this.canTriggerWeeds()) {
target.applyGrowthTick();
type = "positive";
}
}
}
this.spawnParticles(world, pos, type, random);
if ((entity instanceof PlayerEntity) && !(((PlayerEntity) entity).isCreative())) {
stack.shrink(1);
}
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}
use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.
the class MessageSyncResearchCapability method processMessage.
@Override
protected void processMessage(NetworkEvent.Context ctx) {
PlayerEntity player = AgriCraft.instance.getClientPlayer();
if (player != null && this.tag != null) {
CapabilityResearchedPlants.getInstance().getCapability(player).ifPresent(impl -> {
impl.readFromNBT(this.tag);
impl.configureJei();
});
}
}
Aggregations