Update state of pattern storage
This commit is contained in:
parent
51faf655b9
commit
090d2ac385
@ -48,7 +48,7 @@ public class BlockPatternStorage extends BlockMatteryRotatable implements Entity
|
|||||||
var state = super.getStateForPlacement(context);
|
var state = super.getStateForPlacement(context);
|
||||||
|
|
||||||
for (var prop : PATTERN_STORAGE_DISKS_PROPS)
|
for (var prop : PATTERN_STORAGE_DISKS_PROPS)
|
||||||
state = state.setValue(prop, Math.random() > 0.5);
|
state = state.setValue(prop, false);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,14 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
|
import ru.dbotthepony.mc.otm.block.BlockPatternStorage;
|
||||||
import ru.dbotthepony.mc.otm.capability.*;
|
import ru.dbotthepony.mc.otm.capability.*;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
@ -34,7 +36,7 @@ public class BlockEntityPatternStorage extends BlockEntityMattery implements IMa
|
|||||||
super(Registry.BlockEntities.PATTERN_STORAGE, p_155229_, p_155230_);
|
super(Registry.BlockEntities.PATTERN_STORAGE, p_155229_, p_155230_);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final MatteryContainer patterns = new MatteryContainer(this::setChanged, 3 * 3) {
|
public final MatteryContainer patterns = new MatteryContainer(this::setChanged, 8) {
|
||||||
@Override
|
@Override
|
||||||
public void setChanged(int slot, ItemStack new_state, ItemStack old_state) {
|
public void setChanged(int slot, ItemStack new_state, ItemStack old_state) {
|
||||||
if (grid != null && !ItemStack.isSameItemSameTags(new_state, old_state)) {
|
if (grid != null && !ItemStack.isSameItemSameTags(new_state, old_state)) {
|
||||||
@ -45,6 +47,8 @@ public class BlockEntityPatternStorage extends BlockEntityMattery implements IMa
|
|||||||
if (!new_state.isEmpty()) {
|
if (!new_state.isEmpty()) {
|
||||||
new_state.getCapability(MatteryCapability.PATTERN).ifPresent(cap -> cap.getStoredPatterns().forEach(grid::onPatternAdded));
|
new_state.getCapability(MatteryCapability.PATTERN).ifPresent(cap -> cap.getStoredPatterns().forEach(grid::onPatternAdded));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBlockstate();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.setChanged(slot, new_state, old_state);
|
super.setChanged(slot, new_state, old_state);
|
||||||
@ -56,6 +60,21 @@ public class BlockEntityPatternStorage extends BlockEntityMattery implements IMa
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void updateBlockstate() {
|
||||||
|
if (level == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var state = getBlockState();
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
state = state.setValue(BlockPatternStorage.PATTERN_STORAGE_DISKS_PROPS[i], patterns.getItem(i).getCapability(MatteryCapability.PATTERN).isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != getBlockState()) {
|
||||||
|
level.setBlock(getBlockPos(), state, Block.UPDATE_CLIENTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final LazyOptional<IItemHandler> resolver_item = LazyOptional.of(() -> patterns.handler(
|
private final LazyOptional<IItemHandler> resolver_item = LazyOptional.of(() -> patterns.handler(
|
||||||
((slot, stack) -> stack.getCapability(MatteryCapability.PATTERN).isPresent())
|
((slot, stack) -> stack.getCapability(MatteryCapability.PATTERN).isPresent())
|
||||||
));
|
));
|
||||||
|
@ -17,9 +17,9 @@ public class PatternStorageMenu extends MatteryMenu {
|
|||||||
|
|
||||||
Container patterns = tile != null ? tile.patterns : new SimpleContainer(3 * 3);
|
Container patterns = tile != null ? tile.patterns : new SimpleContainer(3 * 3);
|
||||||
|
|
||||||
for (int row = 0; row < 3; row++)
|
for (int row = 0; row < 2; row++)
|
||||||
for (int column = 0; column < 3; column++)
|
for (int column = 0; column < 4; column++)
|
||||||
addSlot(new PatternSlot(patterns, row * 3 + column, 64 + column * 18, 20 + row * 18));
|
addSlot(new PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24));
|
||||||
|
|
||||||
addInventorySlots();
|
addInventorySlots();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user