Cleanup / minor improvements to the chunk loader.

This commit is contained in:
modmuss50 2019-08-30 18:12:17 +01:00
parent 3f4e53e259
commit 0724c2017a
5 changed files with 17 additions and 51 deletions

View file

@ -34,11 +34,13 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.commons.lang3.StringUtils;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider; import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.containerBuilder.IContainerProvider; import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer; import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder; import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity; import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
@ -48,10 +50,11 @@ import reborncore.common.chunkloading.ChunkLoaderManager;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider { public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider {
public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(1, "ChunkLoaderBlockEntity", 64, this); public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(0, "ChunkLoaderBlockEntity", 64, this);
private int radius; private int radius;
private String ownerUdid;
public ChunkLoaderBlockEntity() { public ChunkLoaderBlockEntity() {
super(TRBlockEntities.CHUNK_LOADER ); super(TRBlockEntities.CHUNK_LOADER );
@ -95,7 +98,7 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
ChunkPos loadPos = new ChunkPos(rootPos.x + i, rootPos.z + j); ChunkPos loadPos = new ChunkPos(rootPos.x + i, rootPos.z + j);
if(!manager.isChunkLoaded(getWorld(), loadPos, getPos())){ if(!manager.isChunkLoaded(getWorld(), loadPos, getPos())){
manager.loadChunk(getWorld(), loadPos, getPos(), "todo"); manager.loadChunk(getWorld(), loadPos, getPos(), ownerUdid);
} }
} }
} }
@ -116,6 +119,7 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
if(world.isClient){ if(world.isClient){
return; return;
} }
ownerUdid = placer.getUuidAsString();
reload(); reload();
} }
@ -140,34 +144,13 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
public void fromTag(CompoundTag nbttagcompound) { public void fromTag(CompoundTag nbttagcompound) {
super.fromTag(nbttagcompound); super.fromTag(nbttagcompound);
this.radius = nbttagcompound.getInt("radius"); this.radius = nbttagcompound.getInt("radius");
this.ownerUdid = nbttagcompound.getString("ownerUdid");
if(!StringUtils.isBlank(ownerUdid)){
nbttagcompound.putString("ownerUdid", this.ownerUdid);
}
inventory.read(nbttagcompound); inventory.read(nbttagcompound);
} }
@Override
public double getBaseMaxPower() {
return TechRebornConfig.chunkLoaderMaxEnergy;
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return false;
}
@Override
public double getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
return TechRebornConfig.chunkLoaderMaxInput;
}
@Override @Override
public RebornInventory<ChunkLoaderBlockEntity> getInventory() { public RebornInventory<ChunkLoaderBlockEntity> getInventory() {
return this.inventory; return this.inventory;
@ -184,7 +167,7 @@ public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements
@Override @Override
public BuiltContainer createContainer(int syncID, PlayerEntity player) { public BuiltContainer createContainer(int syncID, PlayerEntity player) {
return new ContainerBuilder("chunkloader").player(player.inventory).inventory().hotbar().addInventory() return new ContainerBuilder("chunkloader").player(player.inventory).inventory().hotbar().addInventory()
.blockEntity(this).energySlot(0, 8, 72).syncEnergyValue().syncIntegerValue(this::getRadius, this::setRadius).addInventory().create(this, syncID); .blockEntity(this).syncIntegerValue(this::getRadius, this::setRadius).addInventory().create(this, syncID);
} }
} }

View file

@ -108,7 +108,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
@Override @Override
public CompoundTag toTag(CompoundTag nbttagcompound) { public CompoundTag toTag(CompoundTag nbttagcompound) {
super.toTag(nbttagcompound); super.toTag(nbttagcompound);
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) { if (ownerUdid == null || StringUtils.isEmpty(ownerUdid)) {
return nbttagcompound; return nbttagcompound;
} }
nbttagcompound.putString("ownerUdid", this.ownerUdid); nbttagcompound.putString("ownerUdid", this.ownerUdid);

View file

@ -51,7 +51,7 @@ public class GuiChunkLoader extends GuiBase<BuiltContainer> {
addButton(new GuiButtonUpDown(left + 64 + 24, top + 40, this, b -> onClick(-1), UpDownButtonType.REWIND)); addButton(new GuiButtonUpDown(left + 64 + 24, top + 40, this, b -> onClick(-1), UpDownButtonType.REWIND));
addButton(new GuiButtonUpDown(left + 64 + 36, top + 40, this, b -> onClick(-5), UpDownButtonType.FASTREWIND)); addButton(new GuiButtonUpDown(left + 64 + 36, top + 40, this, b -> onClick(-5), UpDownButtonType.FASTREWIND));
addButton(new GuiButtonSimple(left + 30, top + 70, 140, 20, "Toggle Loaded Chunks", b -> ClientChunkManager.toggleLoadedChunks(blockEntity.getPos()))); addButton(new GuiButtonSimple(left + 10, top + 70, 155, 20, "Toggle Loaded Chunks", b -> ClientChunkManager.toggleLoadedChunks(blockEntity.getPos())));
} }
@Override @Override
@ -59,23 +59,13 @@ public class GuiChunkLoader extends GuiBase<BuiltContainer> {
super.drawBackground(partialTicks, mouseX, mouseY); super.drawBackground(partialTicks, mouseX, mouseY);
final Layer layer = Layer.BACKGROUND; final Layer layer = Layer.BACKGROUND;
// Battery slot
drawSlot(8, 72, layer);
if (GuiBase.slotConfigType != GuiBase.SlotConfigType.NONE) { if (GuiBase.slotConfigType != GuiBase.SlotConfigType.NONE) {
return; return;
} }
String text = "Raidus: " + String.valueOf(blockEntity.getRadius()); String text = "Radius: " + blockEntity.getRadius();
drawCentredString(text, 25, 4210752, layer); drawCentredString(text, 25, 4210752, layer);
} }
@Override
protected void drawForeground(final int mouseX, final int mouseY) {
super.drawForeground(mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
builder.drawMultiEnergyBar(this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
}
public void onClick(int amount){ public void onClick(int amount){
NetworkManager.sendToServer(ServerboundPackets.createPacketChunkloader(amount, blockEntity, ClientChunkManager.hasChunksForLoader(blockEntity.getPos()))); NetworkManager.sendToServer(ServerboundPackets.createPacketChunkloader(amount, blockEntity, ClientChunkManager.hasChunksForLoader(blockEntity.getPos())));
} }

View file

@ -314,12 +314,6 @@ public class TechRebornConfig {
@Config(config = "machines", category = "rolling_machine", key = "RollingMachineMaxEnergy", comment = "Rolling Machine Max Energy (Value in EU)") @Config(config = "machines", category = "rolling_machine", key = "RollingMachineMaxEnergy", comment = "Rolling Machine Max Energy (Value in EU)")
public static int rollingMachineMaxEnergy = 10000; public static int rollingMachineMaxEnergy = 10000;
@Config(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxInput", comment = "Chunk Loader Max Input")
public static int chunkLoaderMaxInput = 32;
@Config(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxEnergy", comment = "Chunk Loader Max Energy")
public static int chunkLoaderMaxEnergy = 10_000;
@Config(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxRadius", comment = "Chunk Loader Max Radius") @Config(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxRadius", comment = "Chunk Loader Max Radius")
public static int chunkLoaderMaxRadius = 5; public static int chunkLoaderMaxRadius = 5;

View file

@ -46,7 +46,6 @@ public class StackWIPHandler {
public static void setup() { public static void setup() {
wipBlocks.add(TRContent.Machine.MAGIC_ENERGY_ABSORBER.block); wipBlocks.add(TRContent.Machine.MAGIC_ENERGY_ABSORBER.block);
wipBlocks.add(TRContent.Machine.CHUNK_LOADER.block);
wipBlocks.add(TRContent.Machine.MAGIC_ENERGY_CONVERTER.block); wipBlocks.add(TRContent.Machine.MAGIC_ENERGY_CONVERTER.block);
addHead("modmuss50"); addHead("modmuss50");