Matter bottler
This commit is contained in:
parent
a26ed5ec41
commit
eab7e1de10
@ -82,6 +82,7 @@ public class Registry {
|
|||||||
public static final ResourceLocation MATTER_SCANNER = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_scanner");
|
public static final ResourceLocation MATTER_SCANNER = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_scanner");
|
||||||
public static final ResourceLocation MATTER_PANEL = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_panel");
|
public static final ResourceLocation MATTER_PANEL = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_panel");
|
||||||
public static final ResourceLocation MATTER_REPLICATOR = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_replicator");
|
public static final ResourceLocation MATTER_REPLICATOR = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_replicator");
|
||||||
|
public static final ResourceLocation MATTER_BOTTLER = new ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_bottler");
|
||||||
|
|
||||||
// capabilities
|
// capabilities
|
||||||
public static final ResourceLocation ANDROID_CAPABILITY = new ResourceLocation(OverdriveThatMatters.MOD_ID, "android_capability");
|
public static final ResourceLocation ANDROID_CAPABILITY = new ResourceLocation(OverdriveThatMatters.MOD_ID, "android_capability");
|
||||||
@ -126,6 +127,7 @@ public class Registry {
|
|||||||
public static final Block MATTER_SCANNER = new BlockMatterScanner();
|
public static final Block MATTER_SCANNER = new BlockMatterScanner();
|
||||||
public static final Block MATTER_PANEL = new BlockMatterPanel();
|
public static final Block MATTER_PANEL = new BlockMatterPanel();
|
||||||
public static final Block MATTER_REPLICATOR = new BlockMatterReplicator();
|
public static final Block MATTER_REPLICATOR = new BlockMatterReplicator();
|
||||||
|
public static final Block MATTER_BOTTLER = new BlockMatterBottler();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
||||||
@ -137,6 +139,7 @@ public class Registry {
|
|||||||
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
||||||
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
||||||
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
||||||
|
MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@ -150,6 +153,7 @@ public class Registry {
|
|||||||
event.getRegistry().register(MATTER_SCANNER);
|
event.getRegistry().register(MATTER_SCANNER);
|
||||||
event.getRegistry().register(MATTER_PANEL);
|
event.getRegistry().register(MATTER_PANEL);
|
||||||
event.getRegistry().register(MATTER_REPLICATOR);
|
event.getRegistry().register(MATTER_REPLICATOR);
|
||||||
|
event.getRegistry().register(MATTER_BOTTLER);
|
||||||
|
|
||||||
// OverdriveThatMatters.LOGGER.info("Registered blocks");
|
// OverdriveThatMatters.LOGGER.info("Registered blocks");
|
||||||
}
|
}
|
||||||
@ -165,6 +169,7 @@ public class Registry {
|
|||||||
public static final Item MATTER_SCANNER = new BlockItem(Blocks.MATTER_SCANNER, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
public static final Item MATTER_SCANNER = new BlockItem(Blocks.MATTER_SCANNER, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||||
public static final Item MATTER_PANEL = new BlockItem(Blocks.MATTER_PANEL, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
public static final Item MATTER_PANEL = new BlockItem(Blocks.MATTER_PANEL, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||||
public static final Item MATTER_REPLICATOR = new BlockItem(Blocks.MATTER_REPLICATOR, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
public static final Item MATTER_REPLICATOR = new BlockItem(Blocks.MATTER_REPLICATOR, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||||
|
public static final Item MATTER_BOTTLER = new BlockItem(Blocks.MATTER_BOTTLER, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB));
|
||||||
|
|
||||||
public static final ItemPill PILL_ANDROID = new ItemPill(ItemPill.PillType.BECOME_ANDROID);
|
public static final ItemPill PILL_ANDROID = new ItemPill(ItemPill.PillType.BECOME_ANDROID);
|
||||||
public static final ItemPill PILL_HUMANE = new ItemPill(ItemPill.PillType.BECOME_HUMANE);
|
public static final ItemPill PILL_HUMANE = new ItemPill(ItemPill.PillType.BECOME_HUMANE);
|
||||||
@ -194,6 +199,7 @@ public class Registry {
|
|||||||
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
||||||
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
||||||
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
||||||
|
MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER);
|
||||||
|
|
||||||
PILL_ANDROID.setRegistryName(Names.PILL_ANDROID);
|
PILL_ANDROID.setRegistryName(Names.PILL_ANDROID);
|
||||||
PILL_HUMANE.setRegistryName(Names.PILL_HUMANE);
|
PILL_HUMANE.setRegistryName(Names.PILL_HUMANE);
|
||||||
@ -224,6 +230,7 @@ public class Registry {
|
|||||||
event.getRegistry().register(MATTER_SCANNER);
|
event.getRegistry().register(MATTER_SCANNER);
|
||||||
event.getRegistry().register(MATTER_PANEL);
|
event.getRegistry().register(MATTER_PANEL);
|
||||||
event.getRegistry().register(MATTER_REPLICATOR);
|
event.getRegistry().register(MATTER_REPLICATOR);
|
||||||
|
event.getRegistry().register(MATTER_BOTTLER);
|
||||||
|
|
||||||
event.getRegistry().register(PILL_ANDROID);
|
event.getRegistry().register(PILL_ANDROID);
|
||||||
event.getRegistry().register(PILL_HUMANE);
|
event.getRegistry().register(PILL_HUMANE);
|
||||||
@ -256,6 +263,7 @@ public class Registry {
|
|||||||
public static final BlockEntityType<BlockEntityMatterScanner> MATTER_SCANNER = BlockEntityType.Builder.of(BlockEntityMatterScanner::new, Blocks.MATTER_SCANNER).build(null);
|
public static final BlockEntityType<BlockEntityMatterScanner> MATTER_SCANNER = BlockEntityType.Builder.of(BlockEntityMatterScanner::new, Blocks.MATTER_SCANNER).build(null);
|
||||||
public static final BlockEntityType<BlockEntityMatterPanel> MATTER_PANEL = BlockEntityType.Builder.of(BlockEntityMatterPanel::new, Blocks.MATTER_PANEL).build(null);
|
public static final BlockEntityType<BlockEntityMatterPanel> MATTER_PANEL = BlockEntityType.Builder.of(BlockEntityMatterPanel::new, Blocks.MATTER_PANEL).build(null);
|
||||||
public static final BlockEntityType<BlockEntityMatterReplicator> MATTER_REPLICATOR = BlockEntityType.Builder.of(BlockEntityMatterReplicator::new, Blocks.MATTER_REPLICATOR).build(null);
|
public static final BlockEntityType<BlockEntityMatterReplicator> MATTER_REPLICATOR = BlockEntityType.Builder.of(BlockEntityMatterReplicator::new, Blocks.MATTER_REPLICATOR).build(null);
|
||||||
|
public static final BlockEntityType<BlockEntityMatterBottler> MATTER_BOTTLER = BlockEntityType.Builder.of(BlockEntityMatterBottler::new, Blocks.MATTER_BOTTLER).build(null);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
||||||
@ -267,6 +275,7 @@ public class Registry {
|
|||||||
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
||||||
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
||||||
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
||||||
|
MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@ -280,6 +289,7 @@ public class Registry {
|
|||||||
event.getRegistry().register(MATTER_SCANNER);
|
event.getRegistry().register(MATTER_SCANNER);
|
||||||
event.getRegistry().register(MATTER_PANEL);
|
event.getRegistry().register(MATTER_PANEL);
|
||||||
event.getRegistry().register(MATTER_REPLICATOR);
|
event.getRegistry().register(MATTER_REPLICATOR);
|
||||||
|
event.getRegistry().register(MATTER_BOTTLER);
|
||||||
|
|
||||||
// OverdriveThatMatters.LOGGER.info("Registered block entities");
|
// OverdriveThatMatters.LOGGER.info("Registered block entities");
|
||||||
}
|
}
|
||||||
@ -418,6 +428,7 @@ public class Registry {
|
|||||||
public static final MenuType<MatterScannerMenu> MATTER_SCANNER = new MenuType<>(MatterScannerMenu::new);
|
public static final MenuType<MatterScannerMenu> MATTER_SCANNER = new MenuType<>(MatterScannerMenu::new);
|
||||||
public static final MenuType<MatterPanelMenu> MATTER_PANEL = new MenuType<>(MatterPanelMenu::new);
|
public static final MenuType<MatterPanelMenu> MATTER_PANEL = new MenuType<>(MatterPanelMenu::new);
|
||||||
public static final MenuType<MatterReplicatorMenu> MATTER_REPLICATOR = new MenuType<>(MatterReplicatorMenu::new);
|
public static final MenuType<MatterReplicatorMenu> MATTER_REPLICATOR = new MenuType<>(MatterReplicatorMenu::new);
|
||||||
|
public static final MenuType<MatterBottlerMenu> MATTER_BOTTLER = new MenuType<>(MatterBottlerMenu::new);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
||||||
@ -428,6 +439,7 @@ public class Registry {
|
|||||||
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
MATTER_SCANNER.setRegistryName(Names.MATTER_SCANNER);
|
||||||
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
MATTER_PANEL.setRegistryName(Names.MATTER_PANEL);
|
||||||
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR);
|
||||||
|
MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@ -440,6 +452,7 @@ public class Registry {
|
|||||||
event.getRegistry().register(MATTER_SCANNER);
|
event.getRegistry().register(MATTER_SCANNER);
|
||||||
event.getRegistry().register(MATTER_PANEL);
|
event.getRegistry().register(MATTER_PANEL);
|
||||||
event.getRegistry().register(MATTER_REPLICATOR);
|
event.getRegistry().register(MATTER_REPLICATOR);
|
||||||
|
event.getRegistry().register(MATTER_BOTTLER);
|
||||||
|
|
||||||
// OverdriveThatMatters.LOGGER.info("Registered menus");
|
// OverdriveThatMatters.LOGGER.info("Registered menus");
|
||||||
}
|
}
|
||||||
@ -454,6 +467,7 @@ public class Registry {
|
|||||||
MenuScreens.register(MATTER_SCANNER, MatterScannerScreen::new);
|
MenuScreens.register(MATTER_SCANNER, MatterScannerScreen::new);
|
||||||
MenuScreens.register(MATTER_PANEL, MatterPanelScreen::new);
|
MenuScreens.register(MATTER_PANEL, MatterPanelScreen::new);
|
||||||
MenuScreens.register(MATTER_REPLICATOR, MatterReplicatorScreen::new);
|
MenuScreens.register(MATTER_REPLICATOR, MatterReplicatorScreen::new);
|
||||||
|
MenuScreens.register(MATTER_BOTTLER, MatterBottlerScreen::new);
|
||||||
|
|
||||||
// OverdriveThatMatters.LOGGER.info("Registered screens");
|
// OverdriveThatMatters.LOGGER.info("Registered screens");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.EntityBlock;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class BlockMatterBottler extends BlockMatteryRotatable implements EntityBlock {
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||||
|
return new BlockEntityMatterBottler(blockPos, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
||||||
|
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_BOTTLER ? null : BlockEntityMatterBottler::tick;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,315 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.block.entity;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
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 net.minecraftforge.items.IItemHandler;
|
||||||
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.*;
|
||||||
|
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||||
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.MatterBottlerMenu;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class BlockEntityMatterBottler extends BlockEntityMatteryPowered implements IMatterGridCell {
|
||||||
|
public BlockEntityMatterBottler(BlockPos p_155229_, BlockState p_155230_) {
|
||||||
|
super(Registry.BlockEntities.MATTER_BOTTLER, p_155229_, p_155230_);
|
||||||
|
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final TranslatableComponent MACHINE_NAME = new TranslatableComponent("block.overdrive_that_matters.matter_bottler");
|
||||||
|
|
||||||
|
public boolean getWorkFlow() {
|
||||||
|
return work_flow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkFlow(boolean work_flow) {
|
||||||
|
this.work_flow = work_flow;
|
||||||
|
this.setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchWorkFlow() {
|
||||||
|
setWorkFlow(!work_flow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// true - bottling
|
||||||
|
// false - unbottling
|
||||||
|
protected boolean work_flow = true;
|
||||||
|
|
||||||
|
public final MatteryContainer work_slots = new MatteryContainer(this::setChanged, 6) {
|
||||||
|
@Override
|
||||||
|
public int getMaxStackSize(int slot) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public final MatterHandlerCapability matter = new MatterHandlerCapability(this::setChanged, IMatterHandler.MatterDirection.BIDIRECTIONAL, new BigDecimal(4)) {
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public MatterDirection getDirection() {
|
||||||
|
return work_flow ? MatterDirection.RECEIVE : MatterDirection.EXTRACT;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final BigDecimal MATTER_EXCHANGE_RATE = new BigDecimal("0.04");
|
||||||
|
private static final BigDecimal ENERGY_CONSUMPTION = new BigDecimal(20);
|
||||||
|
|
||||||
|
private final LazyOptional<MatterHandlerCapability> matter_resolver = LazyOptional.of(() -> matter);
|
||||||
|
private final LazyOptional<IMatterGridCell> cell_resolver = LazyOptional.of(() -> this);
|
||||||
|
|
||||||
|
private final LazyOptional<IItemHandler> handler_resolver = LazyOptional.of(() -> {
|
||||||
|
return work_slots.handler((slot, stack) -> {
|
||||||
|
if (work_flow) {
|
||||||
|
return slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return slot >= 3 && stack.getCapability(MatteryCapability.MATTER).isPresent();
|
||||||
|
}, (slot, amount, stack) -> {
|
||||||
|
if (work_flow) {
|
||||||
|
return slot >= 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return slot < 3;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
protected BigDecimal initial_capacity;
|
||||||
|
protected ItemStack last_work_stack;
|
||||||
|
|
||||||
|
private MatterGrid grid;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public MatterGrid getMatterGrid() {
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidMatterCell() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMatterGrid(MatterGrid grid) {
|
||||||
|
this.grid = grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IMatterHandler getMatterHandler() {
|
||||||
|
return matter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLevel(Level p_155231_) {
|
||||||
|
super.setLevel(p_155231_);
|
||||||
|
|
||||||
|
if (grid == null)
|
||||||
|
scheduleDiscoverNeighbours(getBlockPos(), p_155231_);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (cap == MatteryCapability.MATTER) {
|
||||||
|
return matter_resolver.cast();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||||
|
return handler_resolver.cast();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap == MatteryCapability.MATTER_CELL) {
|
||||||
|
return cell_resolver.cast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.getCapability(cap, side);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component getDefaultDisplayName() {
|
||||||
|
return MACHINE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) {
|
||||||
|
return new MatterBottlerMenu(containerID, inventory, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag save(CompoundTag nbt) {
|
||||||
|
nbt.put("work_slots", work_slots.serializeNBT());
|
||||||
|
nbt.putBoolean("work_flow", work_flow);
|
||||||
|
nbt.put("matter_capability", matter.serializeNBT());
|
||||||
|
return super.save(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(CompoundTag nbt) {
|
||||||
|
super.load(nbt);
|
||||||
|
work_slots.deserializeNBT(nbt.get("work_slots"));
|
||||||
|
work_flow = nbt.getBoolean("work_flow");
|
||||||
|
|
||||||
|
if (nbt.get("matter_capability") instanceof CompoundTag _matter)
|
||||||
|
matter.deserializeNBT(_matter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final BigDecimal EXTRACTION_TICKS = new BigDecimal(200);
|
||||||
|
|
||||||
|
public float getWorkProgress() {
|
||||||
|
if (last_work_stack == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cap = last_work_stack.getCapability(MatteryCapability.MATTER).resolve();
|
||||||
|
|
||||||
|
if (cap.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cap.get().getStoredMatter().subtract(initial_capacity).divide(cap.get().getMaxStoredMatter().subtract(initial_capacity), MatteryCapability.ROUND_RULES).floatValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T t) {
|
||||||
|
if (t instanceof BlockEntityMatterBottler tile) {
|
||||||
|
tile.batteryChargeLoop();
|
||||||
|
|
||||||
|
ItemStack work_stack = null;
|
||||||
|
IMatterHandler capability = null;
|
||||||
|
int align = tile.work_flow ? 0 : 3;
|
||||||
|
int work_slot = -1;
|
||||||
|
|
||||||
|
for (int i = align; i < align + 3; i++) {
|
||||||
|
var get = tile.work_slots.getItem(i);
|
||||||
|
|
||||||
|
if (!get.isEmpty()) {
|
||||||
|
var cap = get.getCapability(MatteryCapability.MATTER).resolve();
|
||||||
|
|
||||||
|
if (cap.isPresent() && cap.get().getDirection() != (tile.work_flow ? IMatterHandler.MatterDirection.EXTRACT : IMatterHandler.MatterDirection.RECEIVE) && (tile.work_flow ? cap.get().getMissingMatter().compareTo(BigDecimal.ZERO) > 0 : cap.get().getStoredMatter().compareTo(BigDecimal.ZERO) > 0)) {
|
||||||
|
work_stack = get;
|
||||||
|
capability = cap.get();
|
||||||
|
work_slot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (work_stack == null) {
|
||||||
|
tile.last_work_stack = null;
|
||||||
|
tile.initial_capacity = null;
|
||||||
|
} else if (work_stack != tile.last_work_stack) {
|
||||||
|
tile.last_work_stack = work_stack;
|
||||||
|
tile.initial_capacity = capability.getStoredMatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile.work_flow) {
|
||||||
|
if (capability != null) {
|
||||||
|
if (tile.matter.getStoredMatter().compareTo(MATTER_EXCHANGE_RATE) < 0) {
|
||||||
|
if (tile.grid != null) {
|
||||||
|
var extracted = tile.grid.extractMatter(
|
||||||
|
tile.matter.getMissingMatter()
|
||||||
|
.min(MATTER_EXCHANGE_RATE.multiply(EXTRACTION_TICKS))
|
||||||
|
.min(capability.getMissingMatter().subtract(tile.matter.getStoredMatter()))
|
||||||
|
, true);
|
||||||
|
|
||||||
|
if (extracted.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
var received = tile.matter.receiveMatterOuter(extracted, false);
|
||||||
|
tile.grid.extractMatter(received, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile.matter.getStoredMatter().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
var energy = tile.energy.extractEnergyInner(ENERGY_CONSUMPTION, true);
|
||||||
|
|
||||||
|
if (energy.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
var matter = capability.receiveMatterOuter(MATTER_EXCHANGE_RATE.min(tile.matter.getStoredMatter()).multiply(energy.divide(ENERGY_CONSUMPTION, MatteryCapability.ROUND_RULES)), true);
|
||||||
|
|
||||||
|
if (matter.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
tile.energy.extractEnergyInner(ENERGY_CONSUMPTION.multiply(matter.divide(MATTER_EXCHANGE_RATE, MatteryCapability.ROUND_RULES)), false);
|
||||||
|
capability.receiveMatterOuter(matter, false);
|
||||||
|
tile.matter.extractMatterInner(matter, false);
|
||||||
|
|
||||||
|
if (capability.getMissingMatter().compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
for (int i = 3; i < 6; i++) {
|
||||||
|
if (tile.work_slots.getItem(i).isEmpty()) {
|
||||||
|
tile.work_slots.setItem(work_slot, ItemStack.EMPTY);
|
||||||
|
tile.work_slots.setItem(i, work_stack);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (capability != null) {
|
||||||
|
var energy = tile.energy.extractEnergyInner(ENERGY_CONSUMPTION, true);
|
||||||
|
|
||||||
|
if (energy.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
var matter = capability.extractMatterOuter(MATTER_EXCHANGE_RATE.min(tile.matter.getMissingMatter()).multiply(energy.divide(ENERGY_CONSUMPTION, MatteryCapability.ROUND_RULES)), true);
|
||||||
|
|
||||||
|
if (matter.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
tile.energy.extractEnergyInner(ENERGY_CONSUMPTION.multiply(matter.divide(MATTER_EXCHANGE_RATE, MatteryCapability.ROUND_RULES)), false);
|
||||||
|
capability.extractMatterOuter(matter, false);
|
||||||
|
tile.matter.receiveMatterInner(matter, false);
|
||||||
|
|
||||||
|
if (capability.getStoredMatter().compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
if (tile.work_slots.getItem(i).isEmpty()) {
|
||||||
|
tile.work_slots.setItem(work_slot, ItemStack.EMPTY);
|
||||||
|
tile.work_slots.setItem(i, work_stack);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile.matter.getStoredMatter().compareTo(BigDecimal.ZERO) > 0 && tile.grid != null) {
|
||||||
|
BigDecimal diff = tile.matter.extractMatterInner(tile.matter.getStoredMatter(), true);
|
||||||
|
BigDecimal diff2 = tile.grid.softPushMatter(diff, true);
|
||||||
|
|
||||||
|
tile.matter.extractMatterInner(diff2, false);
|
||||||
|
tile.grid.softPushMatter(diff2, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.capability;
|
package ru.dbotthepony.mc.otm.capability;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraftforge.common.util.INBTSerializable;
|
import net.minecraftforge.common.util.INBTSerializable;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ public class MatterHandlerCapability implements IMatterHandler, INBTSerializable
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal receiveMatterOuter(BigDecimal howMuch, boolean simulate) {
|
public BigDecimal receiveMatterOuter(BigDecimal howMuch, boolean simulate) {
|
||||||
if (direction == MatterDirection.EXTRACT)
|
if (getDirection() == MatterDirection.EXTRACT)
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
|
|
||||||
return receiveMatterInner(howMuch, simulate);
|
return receiveMatterInner(howMuch, simulate);
|
||||||
@ -92,7 +93,7 @@ public class MatterHandlerCapability implements IMatterHandler, INBTSerializable
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal extractMatterOuter(BigDecimal howMuch, boolean simulate) {
|
public BigDecimal extractMatterOuter(BigDecimal howMuch, boolean simulate) {
|
||||||
if (direction == MatterDirection.RECEIVE)
|
if (getDirection() == MatterDirection.RECEIVE)
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
|
|
||||||
return extractMatterInner(howMuch, simulate);
|
return extractMatterInner(howMuch, simulate);
|
||||||
|
@ -14,9 +14,9 @@ public class MatteryMachineEnergyStorage implements IMatteryEnergyStorage, INBTS
|
|||||||
CAPACITOR,
|
CAPACITOR,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final BigDecimal DEFAULT_MAX_RECEIVE = new BigDecimal(4000);
|
public static final BigDecimal DEFAULT_MAX_RECEIVE = new BigDecimal(200);
|
||||||
public static final BigDecimal DEFAULT_MAX_EXTRACT = new BigDecimal(4000);
|
public static final BigDecimal DEFAULT_MAX_EXTRACT = new BigDecimal(200);
|
||||||
public static final BigDecimal DEFAULT_MAX_CAPACITY = new BigDecimal(64000);
|
public static final BigDecimal DEFAULT_MAX_CAPACITY = new BigDecimal(60000);
|
||||||
|
|
||||||
protected BigDecimal energy_stored = BigDecimal.ZERO;
|
protected BigDecimal energy_stored = BigDecimal.ZERO;
|
||||||
protected BigDecimal energy_stored_max;
|
protected BigDecimal energy_stored_max;
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.menu;
|
||||||
|
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.inventory.ContainerData;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.widget.MatterLevelWidget;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class MatterBottlerMenu extends PoweredMatteryMenu {
|
||||||
|
public MatterBottlerMenu(int p_38852_, Inventory inventory) {
|
||||||
|
this(p_38852_, inventory, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerData work_flow = new ContainerData() {
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int get(int i) {
|
||||||
|
if (tile != null) {
|
||||||
|
return ((BlockEntityMatterBottler) tile).getWorkFlow() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(int i, int i1) {
|
||||||
|
value = i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public ProgressGaugeWidget progress;
|
||||||
|
public MatterLevelWidget matter_widget;
|
||||||
|
|
||||||
|
public MatterySlot[] work_slots = new MatterySlot[6];
|
||||||
|
|
||||||
|
public MatterBottlerMenu(int p_38852_, Inventory inventory, BlockEntityMatterBottler tile) {
|
||||||
|
super(Registry.Menus.MATTER_BOTTLER, p_38852_, inventory, tile);
|
||||||
|
|
||||||
|
var container = tile != null ? tile.work_slots : new SimpleContainer(6);
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
progress = new ProgressGaugeWidget(this);
|
||||||
|
matter_widget = new MatterLevelWidget(this);
|
||||||
|
} else {
|
||||||
|
progress = new ProgressGaugeWidget(this, tile::getWorkProgress);
|
||||||
|
matter_widget = new MatterLevelWidget(this, tile.matter);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < container.getContainerSize(); i++) {
|
||||||
|
work_slots[i] = new MatterySlot(container, i) {
|
||||||
|
@Override
|
||||||
|
public boolean mayPlace(ItemStack p_40231_) {
|
||||||
|
var cap = p_40231_.getCapability(MatteryCapability.MATTER).resolve();
|
||||||
|
|
||||||
|
if (work_flow.get(0) > 0) {
|
||||||
|
return index < 3 && cap.isPresent() && cap.get().getDirection() != IMatterHandler.MatterDirection.EXTRACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index >= 3 && cap.isPresent() && cap.get().getDirection() != IMatterHandler.MatterDirection.RECEIVE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addSlot(work_slots[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
addDataSlots(work_flow);
|
||||||
|
addBatterySlot();
|
||||||
|
addInventorySlots();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getWorkingSlotStart() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getWorkingSlotEnd() {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,10 @@ public class MatterySlot extends Slot {
|
|||||||
this(p_40223_, index, x, y, true);
|
this(p_40223_, index, x, y, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MatterySlot(Container p_40223_, int index) {
|
||||||
|
this(p_40223_, index, 0, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack last_stack;
|
private ItemStack last_stack;
|
||||||
private ItemStack watching_stack;
|
private ItemStack watching_stack;
|
||||||
|
|
||||||
|
@ -22,6 +22,14 @@ public class MatterLevelWidget extends StorageGaugeWidget {
|
|||||||
super(menu, x, y);
|
super(menu, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MatterLevelWidget(MatteryMenu menu) {
|
||||||
|
this(menu, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MatterLevelWidget(MatteryMenu menu, IMatterHandler capability) {
|
||||||
|
this(menu, 0, 0, capability);
|
||||||
|
}
|
||||||
|
|
||||||
public MatterLevelWidget(MatteryMenu menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
public MatterLevelWidget(MatteryMenu menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||||
super(menu, x, y, value_supplier, max_value_supplier);
|
super(menu, x, y, value_supplier, max_value_supplier);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,14 @@ public class ProgressGaugeWidget extends GaugeWidget {
|
|||||||
this(menu, x, y, null, null);
|
this(menu, x, y, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProgressGaugeWidget(MatteryMenu menu) {
|
||||||
|
this(menu, 0, 0, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProgressGaugeWidget(MatteryMenu menu, Supplier<Float> progress) {
|
||||||
|
this(menu, 0, 0, progress, null);
|
||||||
|
}
|
||||||
|
|
||||||
public ProgressGaugeWidget(MatteryMenu menu, int x, int y, Supplier<Float> progress) {
|
public ProgressGaugeWidget(MatteryMenu menu, int x, int y, Supplier<Float> progress) {
|
||||||
this(menu, x, y, progress, null);
|
this(menu, x, y, progress, null);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.screen;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.MatterBottlerMenu;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
|
||||||
|
import ru.dbotthepony.mc.otm.menu.widget.GaugeWidget;
|
||||||
|
import ru.dbotthepony.mc.otm.screen.panels.FlexGridPanel;
|
||||||
|
import ru.dbotthepony.mc.otm.screen.panels.MatteryWidgetPanel;
|
||||||
|
import ru.dbotthepony.mc.otm.screen.panels.SlotPanel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MatterBottlerScreen extends MatteryScreen<MatterBottlerMenu> implements MatteryScreen.IMatteryScreenGaugeGetter, MatteryScreen.IMatteryScreenBatteryGetter, MatteryScreen.IMatteryScreenGridBased {
|
||||||
|
public MatterBottlerScreen(MatterBottlerMenu menu, Inventory inventory, Component title) {
|
||||||
|
super(menu, inventory, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaugeWidget> getGauges() {
|
||||||
|
return List.of(menu.battery_widget, menu.matter_widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BatterySlot> getBatterySlots() {
|
||||||
|
return List.of(menu.battery_slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createGridPanels(FlexGridPanel grid) {
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[0]);
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[1]);
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[2]);
|
||||||
|
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[3]);
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[4]);
|
||||||
|
new SlotPanel<>(this, grid, menu.work_slots[5]);
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,6 @@ public record SkinElement(ResourceLocation texture, float image_x, float image_y
|
|||||||
float defined_width, float defined_height) {
|
float defined_width, float defined_height) {
|
||||||
public void render(PoseStack stack, float x, float y, float width, float height) {
|
public void render(PoseStack stack, float x, float y, float width, float height) {
|
||||||
RenderSystem.setShaderTexture(0, texture);
|
RenderSystem.setShaderTexture(0, texture);
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
|
|
||||||
RenderHelper.drawTexturedRectUV(
|
RenderHelper.drawTexturedRectUV(
|
||||||
stack,
|
stack,
|
||||||
|
@ -90,6 +90,7 @@
|
|||||||
"block.overdrive_that_matters.matter_scanner": "Matter scanner",
|
"block.overdrive_that_matters.matter_scanner": "Matter scanner",
|
||||||
"block.overdrive_that_matters.matter_panel": "Pattern monitor",
|
"block.overdrive_that_matters.matter_panel": "Pattern monitor",
|
||||||
"block.overdrive_that_matters.matter_replicator": "Matter replicator",
|
"block.overdrive_that_matters.matter_replicator": "Matter replicator",
|
||||||
|
"block.overdrive_that_matters.matter_bottler": "Matter bottler",
|
||||||
|
|
||||||
"otm.container.matter_panel.number_input": "Input replication task count",
|
"otm.container.matter_panel.number_input": "Input replication task count",
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user