Skip to content

Commit

Permalink
AgriCraft + EIO integration + berry metas
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Oct 20, 2023
1 parent ffc3ec2 commit 1274e45
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 16 deletions.
11 changes: 10 additions & 1 deletion src/main/java/gregtechfoodoption/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import crazypants.enderio.api.farm.IFarmerJoe;
import crazypants.enderio.base.farming.farmers.CustomSeedFarmer;
import crazypants.enderio.base.integration.natura.NaturaBerryFarmer;
import gregtech.api.block.VariantItemBlock;
import gregtech.api.recipes.RecipeMaps;
import gregtechfoodoption.block.GTFOBerryBush;
import gregtechfoodoption.block.GTFOCrop;
import gregtechfoodoption.block.GTFOMetaBlocks;
import gregtechfoodoption.block.GTFORootCrop;
import gregtechfoodoption.integration.enderio.GTFOBerryFarmer;
import gregtechfoodoption.integration.enderio.GTFORootCropFarmer;
import gregtechfoodoption.item.GTFOMetaItem;
import gregtechfoodoption.item.GTFOMetaItems;
Expand Down Expand Up @@ -158,7 +161,13 @@ public static void registerEIOFarmerJoes(@Nonnull RegistryEvent.Register<IFarmer
event.getRegistry().register(new GTFORootCropFarmer(crop, crop.getSeedStack())
.setRegistryName(crop.getRegistryName()));
continue;
};
}
if (crop instanceof GTFOBerryBush) {
event.getRegistry().register(new GTFOBerryFarmer(crop, crop.getSeedStack())
.setRegistryName(crop.getRegistryName()));

continue;
}
event.getRegistry().register(new CustomSeedFarmer(crop, crop.getSeedStack())
.setRegistryName(crop.getRegistryName()));
}
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/gregtechfoodoption/block/GTFOBerryBush.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos
Random rand = world instanceof World ? ((World) world).rand : new Random();

if (age >= this.getMaxAge()) {
if (!seed.isEmpty()) {
drops.add(seed.copy());
if (rand.nextInt(9) == 0) {
drops.add(seed.copy());
}
}

for (int i = 0; i < 3 + efficiency; ++i) {
drops.add(this.crop.copy());
for (int i = 0; i < 2 + efficiency; ++i) {
if (rand.nextInt(2) == 0) {
drops.add(this.crop.copy());
}
Expand Down Expand Up @@ -165,12 +159,31 @@ public int getMaxAge() {
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (this.isMaxAge(state)) {
if (!playerIn.addItemStackToInventory(this.getCropStack())) {
int berries = 1;
for (int i = 0; i < 2 + getEfficiency(state); ++i) {
if (worldIn.rand.nextInt(2) == 0) {
berries++;
}
}

ItemStack berryStack = this.getCropStack().copy();
berryStack.setCount(berries);
if (!playerIn.addItemStackToInventory(berryStack)) {
playerIn.dropItem(this.getCropStack(), false);
worldIn.setBlockState(pos, state.withProperty(AGE_GTFO, Integer.valueOf(this.getMaxAge() - 1)), 3);
}
worldIn.setBlockState(pos, state.withProperty(AGE_GTFO, Integer.valueOf(this.getMaxAge() - 1)), 3);
return true;
}
return false;
}

@Override
public IBlockState getStateFromMeta(int meta) {
return this.withAge(meta % 3).withProperty(EFFICIENCY_GTFO, Integer.valueOf(meta / 3));
}

@Override
public int getMetaFromState(IBlockState state) {
return this.getEfficiency(state) * 3 + this.getAge(state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.infinityraider.agricraft.renderers.PlantRenderer;
import com.infinityraider.infinitylib.render.tessellation.ITessellator;
import gregtechfoodoption.GTFOValues;
import gregtechfoodoption.block.GTFOBerryBush;
import gregtechfoodoption.block.GTFOCrop;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand Down Expand Up @@ -86,7 +87,7 @@ public double getSpawnChance() {

@Override
public double getGrowthChanceBase() {
return 0.9;
return wrap instanceof GTFOBerryBush ? 0.05 : 0.9;
}

@Override
Expand All @@ -111,7 +112,7 @@ public double getGrassDropChance() {

@Override
public int getGrowthStages() {
return 6;
return wrap instanceof GTFOBerryBush ? 3 : 6;
}

@Override
Expand All @@ -136,6 +137,9 @@ public ItemStack getSeed() {
@Override
public IGrowthRequirement getGrowthRequirement() {
IGrowthReqBuilder builder = new GrowthReqBuilder();
if (wrap instanceof GTFOBerryBush) {
builder.addSoil(AgriApi.getSoilRegistry().get(Blocks.GRASS.getDefaultState()).get());
}
builder.addSoil(AgriApi.getSoilRegistry().get(Blocks.FARMLAND.getDefaultState()).get()); // How could this go wrong??? :troll:
return builder.build();
}
Expand Down Expand Up @@ -177,8 +181,12 @@ public RenderMethod getRenderMethod() {
@Nullable
@Override
public ResourceLocation getPrimaryPlantTexture(int i) {
int possibleAge = Math.min(i, wrap.getMaxAge()); // Required for clippings to render correctly (they assume all crops have 7 stages... the fools)
return new ResourceLocation(GTFOValues.MODID, "crop/crop_" + this.wrap.getName() + "/stage" + possibleAge);
if (wrap instanceof GTFOBerryBush) {
return i < 3 ? new ResourceLocation(GTFOValues.MODID, "blocks/berry/ungrown") : new ResourceLocation(GTFOValues.MODID, "blocks/berry/" + this.wrap.getName() + "_ripe");
} else {
int possibleAge = Math.min(i, wrap.getMaxAge()); // Required for clippings to render correctly (they assume all crops have 7 stages... the fools)
return new ResourceLocation(GTFOValues.MODID, "crop/crop_" + this.wrap.getName() + "/stage" + possibleAge);
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gregtechfoodoption.integration.enderio;

import com.enderio.core.common.util.NNList;
import crazypants.enderio.api.farm.FarmNotification;
import crazypants.enderio.api.farm.FarmingAction;
import crazypants.enderio.api.farm.IFarmer;
import crazypants.enderio.api.farm.IHarvestResult;
import crazypants.enderio.base.farming.FarmingTool;
import crazypants.enderio.base.farming.farmers.CustomSeedFarmer;
import crazypants.enderio.base.farming.farmers.HarvestResult;
import crazypants.enderio.util.Prep;
import gregtechfoodoption.block.GTFOBerryBush;
import gregtechfoodoption.block.GTFOCrop;
import gregtechfoodoption.block.GTFORootCrop;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class GTFOBerryFarmer extends CustomSeedFarmer {
public GTFOBerryFarmer(@NotNull Block plantedBlock, @NotNull ItemStack seeds) {
super(plantedBlock, seeds);
}

@Nullable
@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
if (!canHarvest(farm, pos, state) || !farm.checkAction(FarmingAction.HARVEST, getHarvestTool())) {
return null;
}
if (!farm.hasTool(getHarvestTool())) {
farm.setNotification(getNoHarvestToolNotification());
return null;
}

final World world = farm.getWorld();
final EntityPlayerMP joe = farm.startUsingItem(getHarvestTool());
final int fortune = farm.getLootingValue(getHarvestTool());
final IHarvestResult res = new HarvestResult(pos);
GTFOCrop crop = (GTFOCrop) state.getBlock();

NNList<ItemStack> drops = new NNList<>();
state.getBlock().getDrops(drops, world, pos, state, fortune);
float chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, pos, state, fortune, 1.0F, false, joe);
farm.registerAction(FarmingAction.HARVEST, getHarvestTool(), state, pos);
for (ItemStack stack : drops) {
if (world.rand.nextFloat() <= chance) {
res.addDrop(pos, stack.copy());
}
}

NNList.wrap(farm.endUsingItem(getHarvestTool())).apply(drop -> {
res.addDrop(pos, drop.copy());
});

world.setBlockState(pos, state.withProperty(crop.AGE_GTFO, Integer.valueOf(crop.getMaxAge() - 1)), 3);
return res;
}

@Override
public boolean canPlant(@NotNull ItemStack stack) {
return false;
}

@Override
public boolean canHarvest(@Nonnull IFarmer farm, @Nonnull BlockPos bc, @Nonnull IBlockState state) {
return state.getBlock() instanceof GTFOCrop crop && crop == getPlantedBlock() && crop.isMaxAge(state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public static void registerDefaultModes() {
registerFarmerMode(new GroundClearingFarmerMode(Blocks.BROWN_MUSHROOM));
registerFarmerMode(new GroundClearingFarmerMode(Blocks.SNOW_LAYER));
registerFarmerMode(new GroundClearingFarmerMode(Blocks.DOUBLE_PLANT));
registerFarmerMode(new GTFOCropFarmerMode());
registerFarmerMode(new GTFORootCropFarmerMode());
registerFarmerMode(new GTFOBerryFarmerMode());
registerFarmerMode(new GTFOCropFarmerMode());
if (Loader.isModLoaded(MODID_AC))
registerFarmerMode(new GTFOAgriCraftFarmerMode());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gregtechfoodoption.machines.farmer;

import gregtechfoodoption.block.GTFOBerryBush;
import gregtechfoodoption.block.GTFOCrop;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class GTFOBerryFarmerMode implements FarmerMode {
@Override
public boolean canOperate(IBlockState state, MetaTileEntityFarmer farmer, BlockPos pos, World world) {
return state.getBlock() instanceof GTFOBerryBush && ((GTFOBerryBush) state.getBlock()).isMaxAge(state);
}

@Override
public boolean canPlaceItem(ItemStack stack) {
return false;
}

@Override
public void harvest(IBlockState state, World world, BlockPos.MutableBlockPos pos, MetaTileEntityFarmer farmer) {
GTFOCrop crop = (GTFOCrop) state.getBlock();
world.setBlockState(pos, state.withProperty(crop.AGE_GTFO, Integer.valueOf(crop.getMaxAge() - 1)), 3);
}
}

0 comments on commit 1274e45

Please sign in to comment.