Skip to content

Commit

Permalink
Work on filler patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed May 18, 2017
1 parent 38e18ba commit 80b276b
Show file tree
Hide file tree
Showing 49 changed files with 691 additions and 457 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 36 additions & 19 deletions common/buildcraft/builders/gui/GuiFiller.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@

import net.minecraft.util.ResourceLocation;

import buildcraft.api.filler.FillerManager;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.statements.IStatementContainer;

import buildcraft.lib.client.sprite.ISprite;
import buildcraft.lib.client.sprite.SpriteAtlas;
import buildcraft.lib.gui.GuiIcon;
import buildcraft.lib.gui.button.GuiButtonSmall;
import buildcraft.lib.gui.button.IButtonBehaviour;
import buildcraft.lib.gui.elem.ToolTip;
import buildcraft.lib.gui.pos.GuiRectangle;
import buildcraft.lib.gui.statement.GuiStatementSelector;

import buildcraft.builders.container.ContainerFiller;

public class GuiFiller extends GuiStatementSelector<ContainerFiller> {
private static final ResourceLocation TEXTURE_BASE =
new ResourceLocation("buildcraftbuilders:textures/gui/filler.png");
private static final int SIZE_X = 176, SIZE_Y = 241;
private static final ResourceLocation TEXTURE_BASE = new ResourceLocation("buildcraftbuilders:textures/gui/filler.png");
private static final int SIZE_X = GUI_WIDTH, SIZE_Y = 241;
private static final GuiIcon ICON_GUI = new GuiIcon(TEXTURE_BASE, 0, 0, SIZE_X, SIZE_Y);

public GuiFiller(ContainerFiller container) {
Expand All @@ -31,27 +35,40 @@ public GuiFiller(ContainerFiller container) {
@Override
public void initGui() {
super.initGui();
buttonList.add(
new GuiButtonSmall(
this,
0,
rootElement.getX() + (xSize - 100) / 2,
rootElement.getY() + 60,
100,
"Can Excavate"
)
.setToolTip(ToolTip.createLocalized("gui.filler.canExcavate"))
.setBehaviour(IButtonBehaviour.TOGGLE)
.setActive(container.tile.canExcavate())
.registerListener((button, buttonId, buttonKey) ->
container.tile.sendCanExcavate(button.isButtonActive())
)
);
buttonList.add(new GuiButtonSmall(this, 0, rootElement.getX() + (xSize - 100) / 2, rootElement.getY() + 60, 100, "Can Excavate").setToolTip(ToolTip.createLocalized("gui.filler.canExcavate"))
.setBehaviour(IButtonBehaviour.TOGGLE).setActive(container.tile.canExcavate()).registerListener((button, buttonId, buttonKey) -> container.tile.sendCanExcavate(button.isButtonActive())));
}

@Override
protected void drawBackgroundLayer(float partialTicks) {
ICON_GUI.drawAt(rootElement);
IFillerPattern[] patterns = FillerManager.registry.getPatterns().toArray(new IFillerPattern[0]);
int i = (int) ((System.currentTimeMillis() / 1000) % patterns.length);
IFillerPattern pattern = patterns[i];

ISprite sprite = new SpriteAtlas(pattern.getGuiSprite());
sprite = sprite.subRelative(4, 4, 8, 8, 16);
GuiIcon icon = new GuiIcon(sprite, 8);
GuiRectangle rect = new GuiRectangle(38, 30, 16, 16);
icon.drawScaledInside(rect.offset(rootElement));
// icon.drawAt(0, 0);
}

@Override
protected void iteratePossible(OnStatement consumer) {
// int tx = 0;
// int ty = 0;
// EnumPipePart last = null;
// consumer.iterate(null, rootElement.offset(-18, 8).resize(18, 18));
// for (TriggerWrapper wrapper : container.possibleTriggers) {
// tx++;
// if (tx > 3 || (last != null && last != wrapper.sourcePart)) {
// tx = 0;
// ty++;
// }
// consumer.iterate(wrapper, rootElement.offset(18 * (-1 - tx), ty * 18 + 8).resize(18, 18));
// last = wrapper.sourcePart;
// }
}

@Override
Expand Down
109 changes: 52 additions & 57 deletions common/buildcraft/builders/tile/TileFiller.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
package buildcraft.builders.tile;

import java.io.IOException;
import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import buildcraft.api.core.EnumPipePart;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.inventory.IItemTransactor;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.mj.MjCapabilityHelper;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.containers.IFillerStatementContainer;
import buildcraft.api.tiles.IDebuggable;
import buildcraft.builders.addon.AddonFillingPlanner;
import buildcraft.builders.filling.Filling;
import buildcraft.builders.snapshot.ITileForTemplateBuilder;
import buildcraft.builders.snapshot.Template;
import buildcraft.builders.snapshot.TemplateBuilder;
import buildcraft.core.marker.volume.EnumAddonSlot;
import buildcraft.core.marker.volume.Lock;
import buildcraft.core.marker.volume.VolumeBox;
import buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes;

import buildcraft.lib.block.BlockBCBase_Neptune;
import buildcraft.lib.misc.BoundingBoxUtil;
import buildcraft.lib.misc.MessageUtil;
Expand All @@ -26,39 +41,23 @@
import buildcraft.lib.tile.item.ItemHandlerManager.EnumAccess;
import buildcraft.lib.tile.item.ItemHandlerSimple;
import buildcraft.lib.tile.item.StackInsertionFunction;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.*;
import buildcraft.builders.addon.AddonFillingPlanner;
import buildcraft.builders.filling.Filling;
import buildcraft.builders.snapshot.ITileForTemplateBuilder;
import buildcraft.builders.snapshot.Template;
import buildcraft.builders.snapshot.TemplateBuilder;
import buildcraft.core.marker.volume.EnumAddonSlot;
import buildcraft.core.marker.volume.Lock;
import buildcraft.core.marker.volume.VolumeBox;
import buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes;

public class TileFiller extends TileBC_Neptune implements ITickable, IDebuggable, ITileForTemplateBuilder {
public class TileFiller extends TileBC_Neptune implements ITickable, IDebuggable, ITileForTemplateBuilder, IFillerStatementContainer {
public static final IdAllocator IDS = TileBC_Neptune.IDS.makeChild("filler");
public static final int NET_CAN_EXCAVATE = IDS.allocId("CAN_EXCAVATE");

public final ItemHandlerSimple invResources =
itemManager.addInvHandler(
"resources",
new ItemHandlerSimple(
27,
(slot, stack) -> Filling.INSTANCE.getItemBlocks().contains(stack.getItem()),
StackInsertionFunction.getDefaultInserter(),
this::onSlotChange
),
EnumAccess.NONE,
EnumPipePart.VALUES
);
public final ItemHandlerSimple invResources = itemManager.addInvHandler("resources", new ItemHandlerSimple(27, (slot, stack) -> Filling.INSTANCE.getItemBlocks().contains(stack.getItem()),
StackInsertionFunction.getDefaultInserter(), this::onSlotChange), EnumAccess.BOTH, EnumPipePart.VALUES);
private final MjBattery battery = new MjBattery(1000 * MjAPI.MJ);
private boolean canExcavate = true;
public AddonFillingPlanner addon;
Expand All @@ -78,23 +77,10 @@ public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
VolumeBox box = volumeBoxes.getBoxAt(pos.offset(blockState.getValue(BlockBCBase_Neptune.PROP_FACING).getOpposite()));
if (box != null) {
addon = (AddonFillingPlanner) box.addons
.values()
.stream()
.filter(AddonFillingPlanner.class::isInstance)
.findFirst()
.orElse(null);
addon = (AddonFillingPlanner) box.addons.values().stream().filter(AddonFillingPlanner.class::isInstance).findFirst().orElse(null);
if (addon != null) {
box.locks.add(
new Lock(
new Lock.Cause.CauseBlock(pos, blockState.getBlock()),
new Lock.Target.TargetResize(),
new Lock.Target.TargetAddon(addon.getSlot()),
new Lock.Target.TargetUsedByMachine(
Lock.Target.TargetUsedByMachine.EnumType.STRIPES_WRITE
)
)
);
box.locks.add(new Lock(new Lock.Cause.CauseBlock(pos, blockState.getBlock()), new Lock.Target.TargetResize(), new Lock.Target.TargetAddon(addon.getSlot()),
new Lock.Target.TargetUsedByMachine(Lock.Target.TargetUsedByMachine.EnumType.STRIPES_WRITE)));
volumeBoxes.markDirty();
}
}
Expand Down Expand Up @@ -167,10 +153,7 @@ public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
battery.deserializeNBT(nbt.getCompoundTag("battery"));
if (nbt.hasKey("addonSlot")) {
addon = (AddonFillingPlanner) WorldSavedDataVolumeBoxes.get(world)
.getBoxFromId(nbt.getUniqueId("addonBoxId"))
.addons
.get(NBTUtilBC.readEnum(nbt.getTag("addonSlot"), EnumAddonSlot.class));
addon = (AddonFillingPlanner) WorldSavedDataVolumeBoxes.get(world).getBoxFromId(nbt.getUniqueId("addonBoxId")).addons.get(NBTUtilBC.readEnum(nbt.getTag("addonSlot"), EnumAddonSlot.class));
}
canExcavate = nbt.getBoolean("canExcavate");
}
Expand Down Expand Up @@ -233,4 +216,16 @@ public Template.BuildingInfo getTemplateBuildingInfo() {
public IItemTransactor getInvResources() {
return invResources;
}

// IFillerStatmentContainer

@Override
public TileEntity getTile() {
return this;
}

@Override
public void setPattern(IFillerPattern pattern, IStatementParameter[] params) {
// TODO!
}
}
19 changes: 17 additions & 2 deletions common/buildcraft/core/BCCoreSprites.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import buildcraft.api.tiles.IControllable;

import buildcraft.lib.client.sprite.SpriteHolderRegistry;
import buildcraft.lib.client.sprite.SpriteHolderRegistry.SpriteHolder;

import buildcraft.core.statements.TriggerFluidContainer;
import buildcraft.core.statements.TriggerFluidContainerLevel;
import buildcraft.core.statements.TriggerInventory;
import buildcraft.core.statements.TriggerInventoryLevel;
import buildcraft.lib.client.sprite.SpriteHolderRegistry;
import buildcraft.lib.client.sprite.SpriteHolderRegistry.SpriteHolder;

public class BCCoreSprites {
public static final SpriteHolder TRIGGER_TRUE;
Expand All @@ -27,6 +28,13 @@ public class BCCoreSprites {
public static final SpriteHolder TRIGGER_POWER_HIGH;
public static final SpriteHolder TRIGGER_POWER_LOW;

public static final SpriteHolder FILLER_NONE;
public static final SpriteHolder FILLER_CLEAR;
public static final SpriteHolder FILLER_FILL;
public static final SpriteHolder FILLER_BOX;
public static final SpriteHolder FILLER_FLATTEN;
public static final SpriteHolder FILLER_HORIZON;

public static final SpriteHolder[] PARAM_REDSTONE_LEVEL;

public static final Map<IControllable.Mode, SpriteHolder> ACTION_MACHINE_CONTROL;
Expand All @@ -49,6 +57,13 @@ public class BCCoreSprites {
TRIGGER_POWER_HIGH = getHolder("triggers/trigger_energy_storage_high");
TRIGGER_POWER_LOW = getHolder("triggers/trigger_energy_storage_low");

FILLER_NONE = getHolder("filler/patterns/none");
FILLER_CLEAR = getHolder("filler/patterns/clear");
FILLER_FILL = getHolder("filler/patterns/fill");
FILLER_BOX = getHolder("filler/patterns/box");
FILLER_FLATTEN = getHolder("filler/patterns/flatten");
FILLER_HORIZON = getHolder("filler/patterns/horizon");

PARAM_REDSTONE_LEVEL = new SpriteHolder[16];
for (int i = 0; i < PARAM_REDSTONE_LEVEL.length; i++) {
PARAM_REDSTONE_LEVEL[i] = getHolder("triggers/parameter_redstone_" + i);
Expand Down
30 changes: 29 additions & 1 deletion common/buildcraft/core/BCCoreStatements.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@
import buildcraft.api.statements.StatementManager;
import buildcraft.api.tiles.IControllable.Mode;

import buildcraft.core.statements.*;
import buildcraft.core.builders.patterns.Pattern;
import buildcraft.core.builders.patterns.PatternBox;
import buildcraft.core.builders.patterns.PatternClear;
import buildcraft.core.builders.patterns.PatternFill;
import buildcraft.core.builders.patterns.PatternNone;
import buildcraft.core.statements.ActionMachineControl;
import buildcraft.core.statements.ActionRedstoneOutput;
import buildcraft.core.statements.BCStatement;
import buildcraft.core.statements.CoreActionProvider;
import buildcraft.core.statements.CoreTriggerProvider;
import buildcraft.core.statements.StatementParamGateSideOnly;
import buildcraft.core.statements.StatementParameterRedstoneLevel;
import buildcraft.core.statements.TriggerFluidContainer;
import buildcraft.core.statements.TriggerFluidContainerLevel;
import buildcraft.core.statements.TriggerInventory;
import buildcraft.core.statements.TriggerInventoryLevel;
import buildcraft.core.statements.TriggerMachine;
import buildcraft.core.statements.TriggerPower;
import buildcraft.core.statements.TriggerRedstoneInput;
import buildcraft.core.statements.TriggerTrue;

public class BCCoreStatements {
public static final TriggerTrue TRIGGER_TRUE = new TriggerTrue();
Expand Down Expand Up @@ -66,6 +85,15 @@ public class BCCoreStatements {
public static final BCStatement[] TRIGGER_INVENTORY_ALL;
public static final BCStatement[] TRIGGER_FLUID_ALL;

public static final PatternNone PATTERN_NONE = new PatternNone();
public static final PatternClear PATTERN_CLEAR = new PatternClear();
public static final PatternFill PATTERN_FILL = new PatternFill();
public static final PatternBox PATTERN_BOX = new PatternBox();

public static final Pattern[] PATTERNS = {//
PATTERN_NONE, PATTERN_CLEAR, PATTERN_FILL, PATTERN_BOX//
};

static {
TRIGGER_INVENTORY_ALL = new BCStatement[7];
System.arraycopy(TRIGGER_INVENTORY, 0, TRIGGER_INVENTORY_ALL, 0, 4);
Expand Down
19 changes: 15 additions & 4 deletions common/buildcraft/core/statements/CoreActionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
import java.util.Arrays;
import java.util.Collection;

import buildcraft.api.tiles.TilesAPI;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;

import buildcraft.api.statements.*;
import buildcraft.api.statements.IActionExternal;
import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IActionInternalSided;
import buildcraft.api.statements.IActionProvider;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.containers.IFillerStatementContainer;
import buildcraft.api.statements.containers.IRedstoneStatementContainer;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.TilesAPI;

import buildcraft.core.BCCoreStatements;

Expand All @@ -32,11 +37,17 @@ public void addInternalSidedActions(Collection<IActionInternalSided> actions, IS

@Override
public void addExternalActions(Collection<IActionExternal> res, EnumFacing side, TileEntity tile) {
if (tile.hasCapability(TilesAPI.CAP_CONTROLLABLE, null)) {
IControllable controllable = tile.getCapability(TilesAPI.CAP_CONTROLLABLE, null);
IControllable controllable = tile.getCapability(TilesAPI.CAP_CONTROLLABLE, side.getOpposite());
if (controllable != null) {
Arrays.stream(BCCoreStatements.ACTION_MACHINE_CONTROL)
.filter(action -> controllable.setControlMode(action.mode, true))
.forEach(res::add);
}
if (tile instanceof IFillerStatementContainer) {
res.add(BCCoreStatements.PATTERN_NONE);
res.add(BCCoreStatements.PATTERN_CLEAR);
res.add(BCCoreStatements.PATTERN_FILL);
res.add(BCCoreStatements.PATTERN_BOX);
}
}
}
4 changes: 2 additions & 2 deletions common/buildcraft/core/tile/TileEngineRedstone_BC8.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public long minPowerReceived() {

@Override
public long maxPowerReceived() {
return MjAPI.MJ;
return 4 * MjAPI.MJ;
}

@Override
public long maxPowerExtracted() {
return MjAPI.MJ;
return 4 * MjAPI.MJ;
}

@Override
Expand Down
Loading

0 comments on commit 80b276b

Please sign in to comment.