Skip to content

Commit

Permalink
Actually fix the isEmpty method this time :)
Browse files Browse the repository at this point in the history
Closes #131
Closes #132
  • Loading branch information
thedarkcolour committed Dec 22, 2024
1 parent 350587f commit 907a7ef
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 48 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Forestry 2.0.3
- Fixed AbstractMethodError with farm and alveary (#131, #132)

## Forestry 2.0.2
- Fixed error when joining server (#130)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,4 @@ public void readGuiData(FriendlyByteBuf data) {
this.temperatureSteps = data.readByte();
this.humiditySteps = data.readByte();
}

// REQUIRED TO AVOID AbstractMethodError crash (issue #129)
@Override
public boolean isEmpty() {
return super.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package forestry.arboriculture.genetics;

import javax.annotation.Nullable;
import java.util.Optional;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;

import forestry.api.apiculture.genetics.IBee;
import forestry.api.arboriculture.genetics.ITree;
import forestry.api.arboriculture.genetics.TreeLifeStage;
import forestry.api.genetics.pollen.ForestryPollenTypes;
import forestry.api.genetics.pollen.IPollen;
import forestry.api.genetics.pollen.IPollenType;
import forestry.arboriculture.blocks.BlockDefaultLeaves;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.config.ForestryConfig;
import forestry.core.utils.SpeciesUtil;
Expand All @@ -27,7 +30,25 @@ public ResourceLocation id() {

@Override
public boolean canPollinate(LevelAccessor level, BlockPos pos, @Nullable Object pollinator) {
return level.getBlockEntity(pos) instanceof TileLeaves || SpeciesUtil.TREE_TYPE.get().getVanillaIndividual(level.getBlockState(pos)) != null;
if (level.getBlockEntity(pos) instanceof TileLeaves) {
return true;
} else {
BlockState state = level.getBlockState(pos);

// Don't pollinate persistent leaves
Optional<Boolean> persistent = state.getOptionalValue(BlockDefaultLeaves.PERSISTENT);
if (persistent.isPresent() && persistent.get()) {
return false;
}

// Don't pollinate decorative leaves
ITree individual = SpeciesUtil.TREE_TYPE.get().getVanillaIndividual(state);
if (individual != null) {
return !individual.getSpecies().getDecorativeLeaves().is(state.getBlock().asItem());
}
}

return false;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ default Level getWorldObj() {
}

@Override
default boolean isEmpty() {
default boolean hasNoParts() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public interface IMultiblockControllerInternal extends IMultiblockController, IN
/**
* @return True if this controller has no associated blocks, false otherwise
*/
boolean isEmpty();
boolean hasNoParts();

/**
* Tests whether this multiblock should consume the other multiblock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ protected final boolean isCoordInMultiblock(int x, int y, int z) {
}

@Override
public boolean isEmpty() {
public boolean hasNoParts() {
return connectedParts.isEmpty();
}

Expand Down Expand Up @@ -694,7 +694,7 @@ public Set<IMultiblockComponent> checkForDisconnections() {
return Collections.emptySet();
}

if (this.isEmpty()) {
if (hasNoParts()) {
MultiblockRegistry.addDeadController(level, this);
return Collections.emptySet();
}
Expand Down Expand Up @@ -744,7 +744,7 @@ public Set<IMultiblockComponent> checkForDisconnections() {
connectedParts.removeAll(deadParts);
deadParts.clear();

if (referencePart == null || isEmpty()) {
if (referencePart == null || hasNoParts()) {
// There are no valid parts remaining. The entire multiblock was unloaded during a chunk unload. Halt.
shouldCheckForDisconnections = false;
MultiblockRegistry.addDeadController(level, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,11 @@ public final void stopOpen(Player player) {
getInternalInventory().stopOpen(player);
}

//TODO inventory title
// @Override
// public String getName() {
// return getInternalInventory().getName();
// }
//
// @Override
// public ITextComponent getDisplayName() {
// return getInternalInventory().getDisplayName();
// }

@Override
public final boolean stillValid(Player player) {
return getInternalInventory().stillValid(player);
}

//TODO inventory title
// @Override
// public boolean hasCustomName() {
// return getInternalInventory().hasCustomName();
// }

@Override
public final boolean canPlaceItem(int slotIndex, ItemStack itemStack) {
return getInternalInventory().canPlaceItem(slotIndex, itemStack);
Expand All @@ -197,24 +180,13 @@ public final boolean canTakeItemThroughFace(int slotIndex, ItemStack itemStack,
return getInternalInventory().canTakeItemThroughFace(slotIndex, itemStack, side);
}

//TODO inventory field
// @Override
// public int getField(int id) {
// return getInternalInventory().getField(id);
// }
//
// @Override
// public int getFieldCount() {
// return getInternalInventory().getFieldCount();
// }
//
// @Override
// public void setField(int id, int value) {
// getInternalInventory().setField(id, value);
// }

@Override
public void clearContent() {
getInternalInventory().clearContent();
}

@Override
public boolean isEmpty() {
return getInternalInventory().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void tickStart() {
if (!controllers.isEmpty()) {
for (IMultiblockControllerInternal controller : controllers) {
if (controller.getWorldObj() == world && controller.getWorldObj().isClientSide == world.isClientSide) {
if (controller.isEmpty()) {
if (controller.hasNoParts()) {
// This happens on the server when the user breaks the last block. It's fine.
// Mark 'er dead and move on.
deadControllers.add(controller);
Expand Down Expand Up @@ -224,7 +224,7 @@ public void processMultiblockChanges() {
// they are no longer connected to this machine.
Set<IMultiblockComponent> newlyDetachedParts = controller.checkForDisconnections();

if (!controller.isEmpty()) {
if (!controller.hasNoParts()) {
controller.recalculateMinMaxCoords();
controller.checkIfMachineIsWhole();
} else {
Expand All @@ -245,7 +245,7 @@ public void processMultiblockChanges() {
for (IMultiblockControllerInternal controller : deadControllers) {
// Go through any controllers which have marked themselves as potentially dead.
// Validate that they are empty/dead, then unregister them.
if (!controller.isEmpty()) {
if (!controller.hasNoParts()) {
Forestry.LOGGER.error("Found a non-empty controller. Forcing it to shed its blocks and die. This should never happen!");
detachedParts.addAll(controller.detachAllBlocks());
}
Expand Down

0 comments on commit 907a7ef

Please sign in to comment.