Make IMatterGridCell be a capability
This commit is contained in:
parent
117d1ea461
commit
25bc104421
@ -18,7 +18,7 @@ import net.minecraft.world.phys.shapes.BooleanOp;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -6,13 +6,17 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.BlockMatterCable;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IPatternStorage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BlockEntityMatterCable extends BlockEntity implements IMatterGridCell {
|
||||
@ -23,6 +27,30 @@ public class BlockEntityMatterCable extends BlockEntity implements IMatterGridCe
|
||||
|
||||
private MatterGrid grid;
|
||||
|
||||
private final LazyOptional<IMatterGridCell> resolver_grid = LazyOptional.of(() -> this);
|
||||
private boolean valid = true;
|
||||
|
||||
@Override
|
||||
public void invalidateCaps() {
|
||||
super.invalidateCaps();
|
||||
valid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reviveCaps() {
|
||||
super.reviveCaps();
|
||||
valid = true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (valid && cap == MatteryCapability.MATTER_CELL)
|
||||
return resolver_grid.cast();
|
||||
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(Level p_155231_) {
|
||||
super.setLevel(p_155231_);
|
||||
@ -68,7 +96,7 @@ public class BlockEntityMatterCable extends BlockEntity implements IMatterGridCe
|
||||
|
||||
@Override
|
||||
public boolean isValidMatterCell() {
|
||||
return !isRemoved();
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,7 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
@ -189,11 +189,18 @@ public class BlockEntityMatterCapacitorBank extends BlockEntityMattery implement
|
||||
valid = true;
|
||||
}
|
||||
|
||||
private final LazyOptional<IMatterGridCell> resolver_grid = LazyOptional.of(() -> this);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (valid && cap == MatteryCapability.MATTER)
|
||||
return resolver.cast();
|
||||
if (valid) {
|
||||
if (cap == MatteryCapability.MATTER)
|
||||
return resolver.cast();
|
||||
|
||||
if (cap == MatteryCapability.MATTER_CELL)
|
||||
return resolver_grid.cast();
|
||||
}
|
||||
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import ru.dbotthepony.mc.otm.*;
|
||||
import ru.dbotthepony.mc.otm.capability.*;
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||
import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu;
|
||||
@ -94,6 +94,8 @@ public class BlockEntityMatterDecomposer extends BlockEntityMatteryPoweredWorker
|
||||
super.invalidateCaps();
|
||||
}
|
||||
|
||||
private final LazyOptional<IMatterGridCell> resolver_grid = LazyOptional.of(() -> this);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
@ -101,6 +103,9 @@ public class BlockEntityMatterDecomposer extends BlockEntityMatteryPoweredWorker
|
||||
if (cap == MatteryCapability.MATTER)
|
||||
return matter_resolver.cast();
|
||||
|
||||
if (cap == MatteryCapability.MATTER_CELL)
|
||||
return resolver_grid.cast();
|
||||
|
||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return handler_resolver.cast();
|
||||
}
|
||||
|
@ -15,13 +15,10 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.*;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||
import ru.dbotthepony.mc.otm.menu.MatterScannerMenu;
|
||||
|
||||
@ -47,11 +44,18 @@ public class BlockEntityMatterScanner extends BlockEntityMatteryPoweredWorker im
|
||||
|
||||
private boolean valid = true;
|
||||
|
||||
private final LazyOptional<IMatterGridCell> resolver_grid = LazyOptional.of(() -> this);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (valid && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return handler_resolver.cast();
|
||||
if (valid) {
|
||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return handler_resolver.cast();
|
||||
|
||||
if (cap == MatteryCapability.MATTER_CELL)
|
||||
return resolver_grid.cast();
|
||||
}
|
||||
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import ru.dbotthepony.mc.otm.matter.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
@ -112,13 +112,15 @@ public class BlockEntityPatternStorage extends BlockEntityMattery implements IMa
|
||||
valid = true;
|
||||
}
|
||||
|
||||
private LazyOptional<BlockEntityPatternStorage> resolver = LazyOptional.of(() -> this);
|
||||
private final LazyOptional<BlockEntityPatternStorage> resolver = LazyOptional.of(() -> this);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
if (cap == MatteryCapability.PATTERN || cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return resolver.cast();
|
||||
if (valid) {
|
||||
if (cap == MatteryCapability.PATTERN || cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || cap == MatteryCapability.MATTER_CELL)
|
||||
return resolver.cast();
|
||||
}
|
||||
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.dbotthepony.mc.otm.matter;
|
||||
package ru.dbotthepony.mc.otm.capability;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -6,8 +6,7 @@ import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -16,10 +15,14 @@ public interface IMatterGridCell {
|
||||
MatterGrid getMatterGrid();
|
||||
|
||||
@Nullable
|
||||
IMatterHandler getMatterHandler();
|
||||
default IMatterHandler getMatterHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
IPatternStorage getPatternStorage();
|
||||
default IPatternStorage getPatternStorage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isValidMatterCell();
|
||||
|
@ -19,6 +19,9 @@ public class MatteryCapability {
|
||||
@CapabilityInject(IMatterHandler.class)
|
||||
public static Capability<IMatterHandler> MATTER = null;
|
||||
|
||||
@CapabilityInject(IMatterGridCell.class)
|
||||
public static Capability<IMatterGridCell> MATTER_CELL = null;
|
||||
|
||||
@CapabilityInject(IPatternStorage.class)
|
||||
public static Capability<IPatternStorage> PATTERN = null;
|
||||
|
||||
@ -27,6 +30,7 @@ public class MatteryCapability {
|
||||
CapabilityManager.INSTANCE.register(IMatteryEnergyStorage.class);
|
||||
CapabilityManager.INSTANCE.register(IMatterHandler.class);
|
||||
CapabilityManager.INSTANCE.register(IPatternStorage.class);
|
||||
CapabilityManager.INSTANCE.register(IMatterGridCell.class);
|
||||
}
|
||||
|
||||
public static final MathContext ROUND_RULES = new MathContext(32, RoundingMode.HALF_DOWN);
|
||||
|
@ -8,6 +8,7 @@ import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fmlserverevents.FMLServerStartedEvent;
|
||||
import net.minecraftforge.fmlserverevents.FMLServerStoppingEvent;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterGridCell;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IPatternStorage;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user