Skip to content

Commit

Permalink
Filler without filling planner, fix #2796
Browse files Browse the repository at this point in the history
  • Loading branch information
afdw committed Jun 29, 2017
1 parent 4d762b8 commit fa1986b
Show file tree
Hide file tree
Showing 17 changed files with 635 additions and 288 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions common/buildcraft/builders/BCBuildersProxy.java
Expand Up @@ -31,8 +31,7 @@
import buildcraft.builders.gui.GuiArchitectTable;
import buildcraft.builders.gui.GuiBuilder;
import buildcraft.builders.gui.GuiElectronicLibrary;
import buildcraft.builders.gui.GuiFiller;
import buildcraft.builders.gui.GuiFillingPlanner;
import buildcraft.builders.gui.GuiFilling;
import buildcraft.builders.gui.GuiReplacer;
import buildcraft.builders.tile.TileArchitectTable;
import buildcraft.builders.tile.TileBuilder;
Expand Down Expand Up @@ -127,7 +126,7 @@ public Object getClientGuiElement(int id, EntityPlayer player, World world, int
if (id == BCBuildersGuis.FILLER.ordinal()) {
if (tile instanceof TileFiller) {
TileFiller filler = (TileFiller) tile;
return new GuiFiller(new ContainerFiller(player, filler));
return new GuiFilling(new ContainerFiller(player, filler));
}
}
if (id == BCBuildersGuis.ARCHITECT.ordinal()) {
Expand All @@ -143,7 +142,7 @@ public Object getClientGuiElement(int id, EntityPlayer player, World world, int
}
}
if (id == BCBuildersGuis.FILLING_PLANNER.ordinal()) {
return new GuiFillingPlanner(new ContainerFillingPlanner(player));
return new GuiFilling(new ContainerFillingPlanner(player));
}
return null;
}
Expand Down
40 changes: 13 additions & 27 deletions common/buildcraft/builders/addon/AddonFillingPlanner.java
Expand Up @@ -14,8 +14,6 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;

import buildcraft.lib.misc.NBTUtilBC;

Expand All @@ -30,25 +28,17 @@
import buildcraft.core.marker.volume.ISingleAddon;

public class AddonFillingPlanner extends Addon implements ISingleAddon {
public List<IParameter> parameters = new ArrayList<>();
public final List<IParameter> parameters = new ArrayList<>();
public boolean inverted;
public Template.BuildingInfo buildingInfo;

public boolean[][][] getFillingPlan() {
BlockPos size = box.box.size();
boolean[][][] fillingPlan = Filling.getFillingPlan(size, parameters);
if (inverted) {
fillingPlan = Filling.invertFillingPlan(size, fillingPlan);
}
return fillingPlan;
}

public void updateBuildingInfo() {
Template template = new Template();
template.size = box.box.size();
template.offset = BlockPos.ORIGIN;
template.data = getFillingPlan();
buildingInfo = template.new BuildingInfo(box.box.min(), Rotation.NONE);
buildingInfo = Filling.createBuildingInfo(
box.box.min(),
box.box.size(),
parameters,
inverted
);
}

@Override
Expand All @@ -64,15 +54,7 @@ public IFastAddonRenderer<AddonFillingPlanner> getRenderer() {

@Override
public void onAdded() {
while (true) {
Class<? extends IParameter> nextParameterClass = Filling.getNextParameterClass(parameters);
if (nextParameterClass != null) {
// noinspection ConstantConditions
parameters.add(nextParameterClass.getEnumConstants()[0]);
} else {
break;
}
}
parameters.addAll(Filling.initParameters());
updateBuildingInfo();
}

Expand All @@ -90,12 +72,16 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
.map(parameter -> IParameter.writeToNBT(new NBTTagCompound(), parameter))
)
);
nbt.setBoolean("inverted", inverted);
return nbt;
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
NBTUtilBC.readCompoundList(nbt.getTag("parameters")).map(IParameter::readFromNBT).forEach(parameters::add);
NBTUtilBC.readCompoundList(nbt.getTag("parameters"))
.map(IParameter::readFromNBT)
.forEach(parameters::add);
inverted = nbt.getBoolean("inverted");
updateBuildingInfo();
}

Expand Down
6 changes: 6 additions & 0 deletions common/buildcraft/builders/block/BlockFiller.java
Expand Up @@ -64,6 +64,12 @@ public TileEntity createNewTileEntity(World world, int meta) {

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileFiller) {
if (!((TileFiller) tile).isValid()) {
return false;
}
}
if (!world.isRemote) {
BCBuildersGuis.FILLER.openGUI(player, pos);
}
Expand Down
39 changes: 36 additions & 3 deletions common/buildcraft/builders/container/ContainerFiller.java
Expand Up @@ -6,6 +6,8 @@

package buildcraft.builders.container;

import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -15,17 +17,18 @@
import buildcraft.lib.gui.slot.SlotBase;

import buildcraft.builders.filling.Filling;
import buildcraft.builders.filling.IParameter;
import buildcraft.builders.tile.TileFiller;

public class ContainerFiller extends ContainerBCTile<TileFiller> {
public class ContainerFiller extends ContainerBCTile<TileFiller> implements IContainerFilling {
public ContainerFiller(EntityPlayer player, TileFiller tile) {
super(player, tile);

addFullPlayerInventory(153);
addFullPlayerInventory(108);

for (int sy = 0; sy < 3; sy++) {
for (int sx = 0; sx < 9; sx++) {
addSlotToContainer(new SlotBase(tile.invResources, sx + sy * 9, 8 + sx * 18, 85 + sy * 18) {
addSlotToContainer(new SlotBase(tile.invResources, sx + sy * 9, sx * 18 + 8, sy * 18 + 40) {
@Override
public boolean isItemValid(@Nonnull ItemStack stack) {
return Filling.getItemBlocks().contains(stack.getItem());
Expand All @@ -35,6 +38,36 @@ public boolean isItemValid(@Nonnull ItemStack stack) {
}
}

@Override
public boolean isInverted() {
return tile.isInverted();
}

@Override
public void setInverted(boolean value) {
tile.sendInverted(value);
}

@Override
public List<IParameter> getParameters() {
return tile.getParameters();
}

@Override
public void setParameters(List<IParameter> value) {
tile.sendParameters(value);
}

@Override
public boolean isCanExcavate() {
return tile.isCanExcavate();
}

@Override
public void setCanExcavate(boolean value) {
tile.sendCanExcavate(value);
}

@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
Expand Down
48 changes: 42 additions & 6 deletions common/buildcraft/builders/container/ContainerFillingPlanner.java
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.stream.IntStream;

import com.google.common.collect.ImmutableList;

import org.apache.commons.lang3.tuple.Pair;

import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -29,13 +31,13 @@
import buildcraft.core.marker.volume.VolumeBox;
import buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes;

public class ContainerFillingPlanner extends ContainerBC_Neptune {
public class ContainerFillingPlanner extends ContainerBC_Neptune implements IContainerFilling {
private static final IdAllocator IDS = ContainerBC_Neptune.IDS.makeChild("filling_planner");
private static final int ID_DATA = IDS.allocId("DATA");

public AddonFillingPlanner addon;
public List<IParameter> parameters = new ArrayList<>();
public boolean inverted;
private List<IParameter> parameters = new ArrayList<>();
private boolean inverted;

public ContainerFillingPlanner(EntityPlayer player) {
super(player);
Expand All @@ -52,7 +54,7 @@ public IdAllocator getIdAllocator() {
return IDS;
}

public void sendDataToServer() {
private void sendDataToServer() {
sendMessage(ID_DATA, buffer -> {
buffer.writeInt(parameters.size());
parameters.forEach(parameter -> IParameter.toBytes(buffer, parameter));
Expand All @@ -66,16 +68,50 @@ public void readMessage(int id, PacketBufferBC buffer, Side side, MessageContext
if (side == Side.SERVER) {
if (id == ID_DATA) {
parameters.clear();
IntStream.range(0, buffer.readInt()).mapToObj(i -> IParameter.fromBytes(buffer)).forEach(parameters::add);
IntStream.range(0, buffer.readInt())
.mapToObj(i -> IParameter.fromBytes(buffer))
.forEach(parameters::add);
inverted = buffer.readBoolean();
addon.parameters = parameters;
addon.parameters.clear();
addon.parameters.addAll(parameters);
addon.inverted = inverted;
addon.updateBuildingInfo();
WorldSavedDataVolumeBoxes.get(player.world).markDirty();
}
}
}

@Override
public boolean isInverted() {
return inverted;
}

@Override
public void setInverted(boolean value) {
inverted = value;
sendDataToServer();
}

@Override
public List<IParameter> getParameters() {
return ImmutableList.copyOf(parameters);
}

@Override
public void setParameters(List<IParameter> value) {
parameters.clear();
parameters.addAll(value);
}

@Override
public boolean isCanExcavate() {
return true;
}

@Override
public void setCanExcavate(boolean value) {
}

@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
Expand Down
25 changes: 25 additions & 0 deletions common/buildcraft/builders/container/IContainerFilling.java
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2017 SpaceToad and the BuildCraft team
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/
*/

package buildcraft.builders.container;

import java.util.List;

import buildcraft.builders.filling.IParameter;

public interface IContainerFilling {
boolean isInverted();

void setInverted(boolean value);

List<IParameter> getParameters();

void setParameters(List<IParameter> value);

boolean isCanExcavate();

void setCanExcavate(boolean value);
}
34 changes: 34 additions & 0 deletions common/buildcraft/builders/filling/Filling.java
Expand Up @@ -17,13 +17,18 @@
import javax.vecmath.Point2d;
import javax.vecmath.Point2i;

import com.google.common.collect.ImmutableList;

import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBlockSpecial;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;

import buildcraft.builders.snapshot.Template;

@SuppressWarnings("WeakerAccess")
public class Filling {
private static List<Item> itemBlocks = new ArrayList<>();
Expand Down Expand Up @@ -156,6 +161,35 @@ public static Class<? extends IParameter> getNextParameterClass(List<IParameter>
return null;
}

public static List<IParameter> initParameters() {
List<IParameter> parameters = new ArrayList<>();
while (true) {
Class<? extends IParameter> nextParameterClass = Filling.getNextParameterClass(parameters);
if (nextParameterClass != null) {
// noinspection ConstantConditions
parameters.add(nextParameterClass.getEnumConstants()[0]);
} else {
break;
}
}
return ImmutableList.copyOf(parameters);
}

public static Template.BuildingInfo createBuildingInfo(BlockPos basePos,
BlockPos size,
List<IParameter> parameters,
boolean inverted) {
Template template = new Template();
template.size = size;
template.offset = BlockPos.ORIGIN;
boolean[][][] fillingPlan = Filling.getFillingPlan(size, parameters);
if (inverted) {
fillingPlan = Filling.invertFillingPlan(size, fillingPlan);
}
template.data = fillingPlan;
return template.new BuildingInfo(basePos, Rotation.NONE);
}

public static boolean[][][] generateFillingPlanByFunction(BlockPos size,
Function<BlockPos, Boolean> function) {
boolean[][][] fillingPlan = new boolean[size.getX()][size.getY()][size.getZ()];
Expand Down

0 comments on commit fa1986b

Please sign in to comment.