mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 11:19:28 +00:00
Speed up the check for if a block position is currently in a greenhouse
This commit is contained in:
1 parent
33d1685713
commit
ca17801c86
2 files changed
+59
-8
No files matched your search
@@ -19,6 +19,7 @@ import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.multiblock.MultiblockRegistry;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.multiblock.InternalBlockCheck;
|
||||
|
||||
public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
|
||||
@@ -28,7 +29,7 @@ public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
for (IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)) {
|
||||
if (controllerInternal instanceof IGreenhouseControllerInternal) {
|
||||
if (controllerInternal.isAssembled()) {
|
||||
if (isPosiotionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)) {
|
||||
if (isPositionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)) {
|
||||
return ((IGreenhouseControllerInternal) controllerInternal).createState();
|
||||
}
|
||||
}
|
||||
@@ -38,13 +39,9 @@ public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isPosiotionInGreenhouse(IGreenhouseControllerInternal controller, BlockPos pos) {
|
||||
for (IInternalBlock internalBlock : controller.getInternalBlocks()) {
|
||||
if (internalBlock.getPos().equals(pos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
private static boolean isPositionInGreenhouse(IGreenhouseControllerInternal controller, BlockPos pos) {
|
||||
IInternalBlock checkBlock = new InternalBlockCheck(pos);
|
||||
return controller.getInternalBlocks().contains(checkBlock);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package forestry.greenhouse.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.greenhouse.IInternalBlockFace;
|
||||
|
||||
/**
|
||||
* Used to check if a blockPos is in a collection of IInternalBlock
|
||||
*/
|
||||
public class InternalBlockCheck implements IInternalBlock {
|
||||
private final BlockPos pos;
|
||||
|
||||
public InternalBlockCheck(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IInternalBlock getRoot() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<IInternalBlockFace> getFaces() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof IInternalBlock)) {
|
||||
return false;
|
||||
}
|
||||
IInternalBlock internalBlock = (IInternalBlock) obj;
|
||||
return internalBlock.getPos().equals(getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return pos.hashCode();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user