Moving to source sets
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.api.util.IOrientableBlock;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class AEBaseBlock extends Block {
|
||||
|
||||
private boolean isInventory = false;
|
||||
|
||||
protected AEBaseBlock(final Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create block properties with some sensible defaults for
|
||||
* AE blocks.
|
||||
*/
|
||||
public static FabricBlockSettings defaultProps(Material material) {
|
||||
return defaultProps(material, material.getColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create block properties with some sensible defaults for
|
||||
* AE blocks.
|
||||
*/
|
||||
public static FabricBlockSettings defaultProps(Material material, MaterialColor color) {
|
||||
return FabricBlockSettings.of(material, color)
|
||||
// These values previousls were encoded in AEBaseBlock
|
||||
.strength(2.2f, 11.f)
|
||||
.breakByTool(FabricToolTags.PICKAXES, 0)
|
||||
.sounds(getDefaultSoundByMaterial(material));
|
||||
}
|
||||
|
||||
private static BlockSoundGroup getDefaultSoundByMaterial(Material mat) {
|
||||
if (mat == AEGlassMaterial.INSTANCE || mat == Material.GLASS) {
|
||||
return BlockSoundGroup.GLASS;
|
||||
} else if (mat == Material.STONE) {
|
||||
return BlockSoundGroup.STONE;
|
||||
} else if (mat == Material.WOOD) {
|
||||
return BlockSoundGroup.WOOD;
|
||||
} else {
|
||||
return BlockSoundGroup.METAL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorOutput(BlockState state) {
|
||||
return this.isInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorOutput(BlockState state, final World worldIn, final BlockPos pos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates around the given Axis (usually the current up axis).
|
||||
*/
|
||||
public boolean rotateAroundFaceAxis(WorldAccess w, BlockPos pos, Direction face) {
|
||||
final IOrientable rotatable = this.getOrientable(w, pos);
|
||||
|
||||
if (rotatable != null && rotatable.canBeRotated()) {
|
||||
if (this.hasCustomRotation()) {
|
||||
this.customRotateBlock(rotatable, face);
|
||||
return true;
|
||||
} else {
|
||||
Direction forward = rotatable.getForward();
|
||||
Direction up = rotatable.getUp();
|
||||
|
||||
for (int rs = 0; rs < 4; rs++) {
|
||||
forward = Platform.rotateAround(forward, face);
|
||||
up = Platform.rotateAround(up, face);
|
||||
|
||||
if (this.isValidOrientation(w, pos, forward, up)) {
|
||||
rotatable.setOrientation(forward, up);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final Direction mapRotation(final IOrientable ori, final Direction dir) {
|
||||
// case DOWN: return bottomIcon;
|
||||
// case UP: return blockIcon;
|
||||
// case NORTH: return northIcon;
|
||||
// case SOUTH: return southIcon;
|
||||
// case WEST: return sideIcon;
|
||||
// case EAST: return sideIcon;
|
||||
|
||||
final Direction forward = ori.getForward();
|
||||
final Direction up = ori.getUp();
|
||||
|
||||
if (forward == null || up == null) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
final int west_x = forward.getOffsetY() * up.getOffsetZ() - forward.getOffsetZ() * up.getOffsetY();
|
||||
final int west_y = forward.getOffsetZ() * up.getOffsetX() - forward.getOffsetX() * up.getOffsetZ();
|
||||
final int west_z = forward.getOffsetX() * up.getOffsetY() - forward.getOffsetY() * up.getOffsetX();
|
||||
|
||||
Direction west = null;
|
||||
for (final Direction dx : Direction.values()) {
|
||||
if (dx.getOffsetX() == west_x && dx.getOffsetY() == west_y && dx.getOffsetZ() == west_z) {
|
||||
west = dx;
|
||||
}
|
||||
}
|
||||
|
||||
if (west == null) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
if (dir == forward) {
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
if (dir == forward.getOpposite()) {
|
||||
return Direction.NORTH;
|
||||
}
|
||||
|
||||
if (dir == up) {
|
||||
return Direction.UP;
|
||||
}
|
||||
if (dir == up.getOpposite()) {
|
||||
return Direction.DOWN;
|
||||
}
|
||||
|
||||
if (dir == west) {
|
||||
return Direction.WEST;
|
||||
}
|
||||
if (dir == west.getOpposite()) {
|
||||
return Direction.EAST;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Identifier id = Registry.BLOCK.getId(this);
|
||||
String regName = id == Registry.BLOCK.getDefaultId() ? "unregistered" : id.getPath();
|
||||
return this.getClass().getSimpleName() + "[" + regName + "]";
|
||||
}
|
||||
|
||||
protected String getUnlocalizedName(final ItemStack is) {
|
||||
return this.getTranslationKey();
|
||||
}
|
||||
|
||||
protected boolean hasCustomRotation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void customRotateBlock(final IOrientable rotatable, final Direction axis) {
|
||||
|
||||
}
|
||||
|
||||
protected IOrientable getOrientable(final BlockView w, final BlockPos pos) {
|
||||
if (this instanceof IOrientableBlock) {
|
||||
IOrientableBlock orientable = (IOrientableBlock) this;
|
||||
return orientable.getOrientable(w, pos);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward,
|
||||
final Direction up) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isInventory() {
|
||||
return this.isInventory;
|
||||
}
|
||||
|
||||
protected void setInventory(final boolean isInventory) {
|
||||
this.isInventory = isInventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.api.util.IOrientableBlock;
|
||||
import appeng.block.misc.LightDetectorBlock;
|
||||
import appeng.block.misc.SkyCompassBlock;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class AEBaseBlockItem extends BlockItem {
|
||||
|
||||
private final AEBaseBlock blockType;
|
||||
|
||||
public AEBaseBlockItem(final Block id, Settings props) {
|
||||
super(id, props);
|
||||
this.blockType = (AEBaseBlock) id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final void appendTooltip(final ItemStack itemStack, final World world, final List<Text> toolTip,
|
||||
final TooltipContext advancedTooltips) {
|
||||
this.addCheckedInformation(itemStack, world, toolTip, advancedTooltips);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void addCheckedInformation(final ItemStack itemStack, final World world, final List<Text> toolTip,
|
||||
final TooltipContext advancedTooltips) {
|
||||
this.blockType.buildTooltip(itemStack, world, toolTip, advancedTooltips);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey(final ItemStack is) {
|
||||
return this.blockType.getTranslationKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult place(ItemPlacementContext context) {
|
||||
|
||||
Direction up = null;
|
||||
Direction forward = null;
|
||||
|
||||
Direction side = context.getSide();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
|
||||
if (this.blockType instanceof AEBaseTileBlock) {
|
||||
if (this.blockType instanceof LightDetectorBlock) {
|
||||
up = side;
|
||||
if (up == Direction.UP || up == Direction.DOWN) {
|
||||
forward = Direction.SOUTH;
|
||||
} else {
|
||||
forward = Direction.UP;
|
||||
}
|
||||
} else if (/* FIXME FABRIC this.blockType instanceof WirelessBlock || */ this.blockType instanceof SkyCompassBlock) {
|
||||
forward = side;
|
||||
if (forward == Direction.UP || forward == Direction.DOWN) {
|
||||
up = Direction.SOUTH;
|
||||
} else {
|
||||
up = Direction.UP;
|
||||
}
|
||||
} else {
|
||||
up = Direction.UP;
|
||||
forward = context.getPlayerFacing().getOpposite();
|
||||
|
||||
if (player != null) {
|
||||
if (player.pitch > 65) {
|
||||
up = forward.getOpposite();
|
||||
forward = Direction.UP;
|
||||
} else if (player.pitch < -65) {
|
||||
up = forward.getOpposite();
|
||||
forward = Direction.DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IOrientable ori = null;
|
||||
if (this.blockType instanceof IOrientableBlock) {
|
||||
ori = ((IOrientableBlock) this.blockType).getOrientable(context.getWorld(), context.getBlockPos());
|
||||
up = side;
|
||||
forward = Direction.SOUTH;
|
||||
if (up.getOffsetY() == 0) {
|
||||
forward = Direction.UP;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.blockType.isValidOrientation(context.getWorld(), context.getBlockPos(), forward, up)) {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
ActionResult result = super.place(context);
|
||||
if (result != ActionResult.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (this.blockType instanceof AEBaseTileBlock && !(this.blockType instanceof LightDetectorBlock)) {
|
||||
final AEBaseBlockEntity tile = ((AEBaseTileBlock<?>) this.blockType).getBlockEntity(context.getWorld(),
|
||||
context.getBlockPos());
|
||||
ori = tile;
|
||||
|
||||
if (tile == null) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (ori.canBeRotated() && !this.blockType.hasCustomRotation()) {
|
||||
ori.setOrientation(forward, up);
|
||||
}
|
||||
|
||||
if (tile instanceof IGridProxyable) {
|
||||
// FIXME FABRIC ((IGridProxyable) tile).getProxy().setOwner(player);
|
||||
}
|
||||
|
||||
tile.onPlacement(context);
|
||||
} else if (this.blockType instanceof IOrientableBlock) {
|
||||
ori.setOrientation(forward, up);
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class AEBaseBlockItemChargeable extends AEBaseBlockItem implements IAEItemPowerStorage {
|
||||
|
||||
public AEBaseBlockItemChargeable(Block id, Settings props) {
|
||||
super(id, props);
|
||||
|
||||
FabricModelPredicateProviderRegistry.register(
|
||||
this,
|
||||
new Identifier(AppEng.MOD_ID, "fill_level"),
|
||||
(is, world, entity) -> {
|
||||
double curPower = getAECurrentPower(is);
|
||||
double maxPower = getAEMaxPower(is);
|
||||
|
||||
return (int) Math.round(100 * curPower / maxPower);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void addCheckedInformation(final ItemStack stack, final World world, final List<Text> lines,
|
||||
final TooltipContext advancedTooltips) {
|
||||
double internalCurrentPower = 0;
|
||||
final double internalMaxPower = this.getMaxEnergyCapacity();
|
||||
|
||||
if (internalMaxPower > 0) {
|
||||
final CompoundTag tag = stack.getTag();
|
||||
if (tag != null) {
|
||||
internalCurrentPower = tag.getDouble("internalCurrentPower");
|
||||
}
|
||||
|
||||
final double percent = internalCurrentPower / internalMaxPower;
|
||||
|
||||
lines.add(GuiText.StoredEnergy.textComponent()
|
||||
.copy()
|
||||
.append(':' + MessageFormat.format(" {0,number,#} ", internalCurrentPower))
|
||||
.append(new TranslatableText(PowerUnits.AE.unlocalizedName))
|
||||
.append(" - " + MessageFormat.format("{0,number,#.##%}", percent)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectAEPower(final ItemStack is, double amount, Actionable mode) {
|
||||
final double internalCurrentPower = this.getInternal(is);
|
||||
final double internalMaxPower = this.getAEMaxPower(is);
|
||||
final double required = internalMaxPower - internalCurrentPower;
|
||||
final double overflow = Math.max(0, amount - required);
|
||||
|
||||
if (mode == Actionable.MODULATE) {
|
||||
final double toAdd = Math.min(required, amount);
|
||||
final double newPowerStored = internalCurrentPower + toAdd;
|
||||
|
||||
this.setInternal(is, newPowerStored);
|
||||
}
|
||||
|
||||
return overflow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(final ItemStack is, double amount, Actionable mode) {
|
||||
final double internalCurrentPower = this.getInternal(is);
|
||||
final double fulfillable = Math.min(amount, internalCurrentPower);
|
||||
|
||||
if (mode == Actionable.MODULATE) {
|
||||
final double newPowerStored = internalCurrentPower - fulfillable;
|
||||
|
||||
this.setInternal(is, newPowerStored);
|
||||
}
|
||||
|
||||
return fulfillable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAEMaxPower(final ItemStack is) {
|
||||
return this.getMaxEnergyCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAECurrentPower(final ItemStack is) {
|
||||
return this.getInternal(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getPowerFlow(final ItemStack is) {
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
|
||||
private double getMaxEnergyCapacity() {
|
||||
final Block blockID = Block.getBlockFromItem(this);
|
||||
final IBlockDefinition energyCell = AEApi.instance().definitions().blocks().energyCell();
|
||||
|
||||
return energyCell.maybeBlock().map(block -> {
|
||||
if (blockID == block) {
|
||||
return 200000;
|
||||
} else {
|
||||
return 8 * 200000;
|
||||
}
|
||||
}).orElse(0);
|
||||
}
|
||||
|
||||
private double getInternal(final ItemStack is) {
|
||||
final CompoundTag nbt = is.getOrCreateTag();
|
||||
return nbt.getDouble("internalCurrentPower");
|
||||
}
|
||||
|
||||
private void setInternal(final ItemStack is, final double amt) {
|
||||
final CompoundTag nbt = is.getOrCreateTag();
|
||||
nbt.putDouble("internalCurrentPower", amt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.AttributeList;
|
||||
import alexiil.mc.lib.attributes.AttributeProvider;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.tile.AEBaseInvBlockEntity;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.tile.storage.SkyChestBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.SettingsFrom;
|
||||
|
||||
public abstract class AEBaseTileBlock<T extends AEBaseBlockEntity> extends AEBaseBlock implements BlockEntityProvider, AttributeProvider {
|
||||
|
||||
@Nonnull
|
||||
private Class<T> blockEntityClass;
|
||||
@Nonnull
|
||||
private Supplier<T> tileEntityFactory;
|
||||
|
||||
public AEBaseTileBlock(final Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
// TODO : Was this change needed?
|
||||
public void setTileEntity(final Class<T> tileEntityClass, Supplier<T> factory) {
|
||||
this.blockEntityClass = tileEntityClass;
|
||||
this.tileEntityFactory = factory;
|
||||
this.setInventory(AEBaseInvBlockEntity.class.isAssignableFrom(tileEntityClass));
|
||||
}
|
||||
|
||||
public Class<T> getBlockEntityClass() {
|
||||
return this.blockEntityClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getBlockEntity(final BlockView w, final int x, final int y, final int z) {
|
||||
return this.getBlockEntity(w, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getBlockEntity(final BlockView w, final BlockPos pos) {
|
||||
|
||||
final BlockEntity te = w.getBlockEntity(pos);
|
||||
// FIXME: This gets called as part of building the block state cache
|
||||
if (this.blockEntityClass != null && this.blockEntityClass.isInstance(te)) {
|
||||
return this.blockEntityClass.cast(te);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world) {
|
||||
return this.tileEntityFactory.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateReplaced(BlockState state, World w, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (newState.getBlock() == state.getBlock()) {
|
||||
return; // Just a block state change
|
||||
}
|
||||
|
||||
final AEBaseBlockEntity te = this.getBlockEntity(w, pos);
|
||||
if (te != null) {
|
||||
final ArrayList<ItemStack> drops = new ArrayList<>();
|
||||
if (te.dropItems()) {
|
||||
te.getDrops(w, pos, drops);
|
||||
} else {
|
||||
te.getNoDrops(w, pos, drops);
|
||||
}
|
||||
|
||||
// Cry ;_; ...
|
||||
Platform.spawnDrops(w, pos, drops);
|
||||
}
|
||||
|
||||
// super will remove the TE, as it is not an instance of BlockContainer
|
||||
super.onStateReplaced(state, w, pos, newState, isMoving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorOutput(BlockState state, final World w, final BlockPos pos) {
|
||||
final BlockEntity te = this.getBlockEntity(w, pos);
|
||||
if (te instanceof AEBaseInvBlockEntity) {
|
||||
AEBaseInvBlockEntity invTile = (AEBaseInvBlockEntity) te;
|
||||
if (invTile.getInternalInventory().getSlotCount() > 0) {
|
||||
return getRedstoneFromFixedItemInv(invTile.getInternalInventory());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate redstone output level.
|
||||
* 0 if completely empty, 1 if _any_ item is present, up to 15 if all slots are full.
|
||||
*/
|
||||
private int getRedstoneFromFixedItemInv(FixedItemInv inv) {
|
||||
boolean foundAnything = false; // ANY slots non-empty?
|
||||
float fillRatio = 0;
|
||||
|
||||
for (int i = 0; i < inv.getSlotCount(); ++i)
|
||||
{
|
||||
ItemStack stack = inv.getInvStack(i);
|
||||
if (stack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int slotMaxCount = inv.getMaxAmount(i, stack);
|
||||
fillRatio += stack.getCount() / (float)Math.min(slotMaxCount, stack.getMaxCount());
|
||||
foundAnything = true;
|
||||
}
|
||||
|
||||
// Average the ratio across all slots
|
||||
fillRatio /= inv.getSlotCount();
|
||||
|
||||
// Always return at least non-zero if _any_ slots are non-empty
|
||||
return (foundAnything ? 1 : 0) + MathHelper.floor(fillRatio * 14.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data) {
|
||||
super.onSyncedBlockEvent(state, world, pos, type, data);
|
||||
final BlockEntity tileentity = world.getBlockEntity(pos);
|
||||
return tileentity != null && tileentity.onSyncedBlockEvent(type, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(final World w, final BlockPos pos, final BlockState state, final LivingEntity placer,
|
||||
final ItemStack is) {
|
||||
// Inherit the item stack's display name, but only if it's a user defined string
|
||||
// rather
|
||||
// than a translation component, since our custom naming cannot handle
|
||||
// untranslated
|
||||
// I18N strings and we would translate it using the server's locale :-(
|
||||
AEBaseBlockEntity te = this.getBlockEntity(w, pos);
|
||||
if (te != null && is.hasCustomName()) {
|
||||
Text displayName = is.getName();
|
||||
if (displayName instanceof LiteralText) {
|
||||
te.setName(((LiteralText) displayName).getRawString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player,
|
||||
Hand hand, BlockHitResult hit) {
|
||||
ItemStack heldItem;
|
||||
if (player != null && !player.getStackInHand(hand).isEmpty()) {
|
||||
heldItem = player.getStackInHand(hand);
|
||||
|
||||
if (Platform.isWrench(player, heldItem, pos) && player.isInSneakingPose()) {
|
||||
final BlockState blockState = world.getBlockState(pos);
|
||||
final Block block = blockState.getBlock();
|
||||
|
||||
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
|
||||
if (tile == null) {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
if (/* FIXME FABRIC tile instanceof CableBusBlockEntity || */ tile instanceof SkyChestBlockEntity) {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
final ItemStack[] itemDropCandidates = Platform.getBlockDrops(world, pos);
|
||||
final ItemStack op = new ItemStack(this);
|
||||
|
||||
for (final ItemStack ol : itemDropCandidates) {
|
||||
if (Platform.itemComparisons().isEqualItemType(ol, op)) {
|
||||
final CompoundTag tag = tile.downloadSettings(SettingsFrom.DISMANTLE_ITEM);
|
||||
if (tag != null) {
|
||||
ol.setTag(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
block.onBreak(world, pos, blockState, player);
|
||||
boolean bl = world.removeBlock(pos, false);
|
||||
if (bl) {
|
||||
block.onBroken(world, pos, blockState);
|
||||
final List<ItemStack> itemsToDrop = Lists.newArrayList(itemDropCandidates);
|
||||
Platform.spawnDrops(world, pos, itemsToDrop);
|
||||
}
|
||||
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
if (heldItem.getItem() instanceof IMemoryCard /* FIXME FABRIC && !(this instanceof CableBusBlock)*/) {
|
||||
final IMemoryCard memoryCard = (IMemoryCard) heldItem.getItem();
|
||||
final AEBaseBlockEntity tileEntity = this.getBlockEntity(world, pos);
|
||||
|
||||
if (tileEntity == null) {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
final String name = this.getTranslationKey();
|
||||
|
||||
if (player.isInSneakingPose()) {
|
||||
final CompoundTag data = tileEntity.downloadSettings(SettingsFrom.MEMORY_CARD);
|
||||
if (data != null) {
|
||||
memoryCard.setMemoryCardContents(heldItem, name, data);
|
||||
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
|
||||
}
|
||||
} else {
|
||||
final String savedName = memoryCard.getSettingsName(heldItem);
|
||||
final CompoundTag data = memoryCard.getData(heldItem);
|
||||
|
||||
if (this.getTranslationKey().equals(savedName)) {
|
||||
tileEntity.uploadSettings(SettingsFrom.MEMORY_CARD, data);
|
||||
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
|
||||
} else {
|
||||
memoryCard.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return this.onActivated(world, pos, player, hand, player.getStackInHand(hand), hit);
|
||||
}
|
||||
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOrientable getOrientable(final BlockView w, final BlockPos pos) {
|
||||
return this.getBlockEntity(w, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the BlockState based on the given BlockState while considering the
|
||||
* state of the given TileEntity.
|
||||
*
|
||||
* If the given TileEntity is not of the right type for this block, the state is
|
||||
* returned unchanged, this is also the case if the given block state does not
|
||||
* belong to this block.
|
||||
*/
|
||||
public final BlockState getBlockEntityBlockState(BlockState current, BlockEntity te) {
|
||||
if (current.getBlock() != this || !blockEntityClass.isInstance(te)) {
|
||||
return current;
|
||||
}
|
||||
|
||||
return updateBlockStateFromTileEntity(current, blockEntityClass.cast(te));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reimplement this in subclasses to allow tile-entities to update the state of
|
||||
* their block when their own state changes.
|
||||
*
|
||||
* It is guaranteed that te is not-null and the block of the given block state
|
||||
* is this exact block instance.
|
||||
*/
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, T te) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
// Gives our tile entity a chance to provide it's attributes
|
||||
@Override
|
||||
public void addAllAttributes(World world, BlockPos pos, BlockState state, AttributeList<?> to) {
|
||||
T te = getBlockEntity(world, pos);
|
||||
if (te != null) {
|
||||
te.addAllAttributes(world, pos, state, to);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.crafting;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.CraftingCPUContainer;
|
||||
import appeng.tile.crafting.CraftingBlockEntity;
|
||||
|
||||
public abstract class AbstractCraftingUnitBlock<T extends CraftingBlockEntity> extends AEBaseTileBlock<T> {
|
||||
public static final BooleanProperty FORMED = BooleanProperty.of("formed");
|
||||
public static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
||||
|
||||
public final CraftingUnitType type;
|
||||
|
||||
public AbstractCraftingUnitBlock(Settings props, final CraftingUnitType type) {
|
||||
super(props);
|
||||
this.type = type;
|
||||
this.setDefaultState(getDefaultState().with(FORMED, false).with(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(POWERED);
|
||||
builder.add(FORMED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(final BlockState state, final World worldIn, final BlockPos pos, final Block blockIn,
|
||||
final BlockPos fromPos, boolean isMoving) {
|
||||
final CraftingBlockEntity cp = this.getBlockEntity(worldIn, pos);
|
||||
if (cp != null) {
|
||||
cp.updateMultiBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateReplaced(BlockState state, World w, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (newState.getBlock() == state.getBlock()) {
|
||||
return; // Just a block state change
|
||||
}
|
||||
|
||||
final CraftingBlockEntity cp = this.getBlockEntity(w, pos);
|
||||
if (cp != null) {
|
||||
cp.breakCluster();
|
||||
}
|
||||
|
||||
super.onStateReplaced(state, w, pos, newState, isMoving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World w, BlockPos pos, PlayerEntity p, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
final CraftingBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
|
||||
if (tg != null && !p.isInSneakingPose() && tg.isFormed() && tg.isActive()) {
|
||||
if (!w.isClient()) {
|
||||
ContainerOpener.openContainer(CraftingCPUContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return super.onUse(state, w, pos, p, hand, hit);
|
||||
}
|
||||
|
||||
public enum CraftingUnitType {
|
||||
UNIT, ACCELERATOR, STORAGE_1K, STORAGE_4K, STORAGE_16K, STORAGE_64K, MONITOR
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.crafting;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.MolecularAssemblerContainer;
|
||||
import appeng.tile.crafting.MolecularAssemblerBlockEntity;
|
||||
|
||||
public class MolecularAssemblerBlock extends AEBaseTileBlock<MolecularAssemblerBlockEntity> {
|
||||
|
||||
public static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
||||
|
||||
public MolecularAssemblerBlock(Settings props) {
|
||||
super(props);
|
||||
setDefaultState(getDefaultState().with(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(POWERED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, MolecularAssemblerBlockEntity te) {
|
||||
return currentState.with(POWERED, te.isPowered());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World w, BlockPos pos, PlayerEntity p, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
final MolecularAssemblerBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null && !p.isInSneakingPose()) {
|
||||
if (!tg.isClient()) {
|
||||
ContainerOpener.openContainer(MolecularAssemblerContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return super.onUse(state, w, pos, p, hand, hit);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.grindstone;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.stats.AeStats;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.tile.grindstone.CrankBlockEntity;
|
||||
|
||||
public class CrankBlock extends AEBaseTileBlock<CrankBlockEntity> {
|
||||
|
||||
public CrankBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (player instanceof FakePlayer || player == null) {
|
||||
this.dropCrank(w, pos);
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
final CrankBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
if (tile.power()) {
|
||||
AeStats.TurnedCranks.addToPlayer(player, 1);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
private void dropCrank(final World world, final BlockPos pos) {
|
||||
world.breakBlock(pos, true);
|
||||
world.updateListeners(pos, this.getDefaultState(), world.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(final World world, final BlockPos pos, final BlockState state,
|
||||
final LivingEntity placer, final ItemStack stack) {
|
||||
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
if (tile != null) {
|
||||
final Direction mnt = this.findCrankable(world, pos);
|
||||
Direction forward = Direction.UP;
|
||||
if (mnt == Direction.UP || mnt == Direction.DOWN) {
|
||||
forward = Direction.SOUTH;
|
||||
}
|
||||
tile.setOrientation(forward, mnt.getOpposite());
|
||||
} else {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
final BlockEntity te = w.getBlockEntity(pos);
|
||||
return !(te instanceof CrankBlockEntity) || this.isCrankable(w, pos, up.getOpposite());
|
||||
}
|
||||
|
||||
private Direction findCrankable(final BlockView world, final BlockPos pos) {
|
||||
for (final Direction dir : Direction.values()) {
|
||||
if (this.isCrankable(world, pos, dir)) {
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isCrankable(final BlockView world, final BlockPos pos, final Direction offset) {
|
||||
final BlockPos o = pos.offset(offset);
|
||||
final BlockEntity te = world.getBlockEntity(o);
|
||||
|
||||
return te instanceof ICrankable && ((ICrankable) te).canCrankAttach(offset.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
if (tile != null) {
|
||||
if (!this.isCrankable(world, pos, tile.getUp().getOpposite())) {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
} else {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
|
||||
return this.findCrankable(w, pos) != null;
|
||||
}
|
||||
|
||||
private Direction getUp(BlockView world, BlockPos pos) {
|
||||
CrankBlockEntity crank = getBlockEntity(world, pos);
|
||||
return crank != null ? crank.getUp() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
Direction up = getUp(world, pos);
|
||||
|
||||
if (up == null) {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
// FIXME: Cache per direction, and build it 'precise', not just from AABB
|
||||
final double xOff = -0.15 * up.getOffsetX();
|
||||
final double yOff = -0.15 * up.getOffsetY();
|
||||
final double zOff = -0.15 * up.getOffsetZ();
|
||||
return VoxelShapes.cuboid(
|
||||
new Box(xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.grindstone;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.GrinderContainer;
|
||||
import appeng.tile.grindstone.GrinderBlockEntity;
|
||||
|
||||
public class GrinderBlock extends AEBaseTileBlock<GrinderBlockEntity> {
|
||||
|
||||
public GrinderBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
final GrinderBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null && !p.isInSneakingPose()) {
|
||||
if (p instanceof ServerPlayerEntity) {
|
||||
ContainerOpener.openContainer(GrinderContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.CellWorkbenchContainer;
|
||||
import appeng.tile.misc.CellWorkbenchBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CellWorkbenchBlock extends AEBaseTileBlock<CellWorkbenchBlockEntity> {
|
||||
|
||||
public CellWorkbenchBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final CellWorkbenchBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
CellWorkbenchContainer.open(p, ContainerLocator.forTileEntity(tg));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.model.json.Transformation;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.util.math.Box;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.AEAxisAlignedBB;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.client.render.effects.ParticleTypes;
|
||||
import appeng.client.render.renderable.ItemRenderable;
|
||||
import appeng.client.render.tesr.ModularTESR;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.tile.misc.ChargerBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ChargerBlock extends AEBaseTileBlock<ChargerBlockEntity> {
|
||||
|
||||
public ChargerBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
|
||||
return 2; // FIXME Double check this (esp. value range)
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (player.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
if (Platform.isServer()) {
|
||||
final ChargerBlockEntity tc = this.getBlockEntity(w, pos);
|
||||
if (tc != null) {
|
||||
tc.activate(player);
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
|
||||
if (!AEConfig.instance().isEnableEffects()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (r.nextFloat() < 0.98) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ChargerBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
if (AEApi.instance().definitions().materials().certusQuartzCrystalCharged()
|
||||
.isSameAs(tile.getInternalInventory().getInvStack(0))) {
|
||||
final double xOff = 0.0;
|
||||
final double yOff = 0.0;
|
||||
final double zOff = 0.0;
|
||||
|
||||
for (int bolts = 0; bolts < 3; bolts++) {
|
||||
if (AppEng.instance().shouldAddParticles(r)) {
|
||||
MinecraftClient.getInstance().particleManager.addParticle(ParticleTypes.LIGHTNING, xOff + 0.5 + pos.getX(),
|
||||
yOff + 0.5 + pos.getY(), zOff + 0.5 + pos.getZ(), 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
|
||||
final ChargerBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
final double twoPixels = 2.0 / 16.0;
|
||||
final Direction up = tile.getUp();
|
||||
final Direction forward = tile.getForward();
|
||||
final AEAxisAlignedBB bb = new AEAxisAlignedBB(twoPixels, twoPixels, twoPixels, 1.0 - twoPixels,
|
||||
1.0 - twoPixels, 1.0 - twoPixels);
|
||||
|
||||
if (up.getOffsetX() != 0) {
|
||||
bb.minX = 0;
|
||||
bb.maxX = 1;
|
||||
}
|
||||
if (up.getOffsetY() != 0) {
|
||||
bb.minY = 0;
|
||||
bb.maxY = 1;
|
||||
}
|
||||
if (up.getOffsetZ() != 0) {
|
||||
bb.minZ = 0;
|
||||
bb.maxZ = 1;
|
||||
}
|
||||
|
||||
switch (forward) {
|
||||
case DOWN:
|
||||
bb.maxY = 1;
|
||||
break;
|
||||
case UP:
|
||||
bb.minY = 0;
|
||||
break;
|
||||
case NORTH:
|
||||
bb.maxZ = 1;
|
||||
break;
|
||||
case SOUTH:
|
||||
bb.minZ = 0;
|
||||
break;
|
||||
case EAST:
|
||||
bb.minX = 0;
|
||||
break;
|
||||
case WEST:
|
||||
bb.maxX = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return VoxelShapes.cuboid(bb.getBoundingBox());
|
||||
}
|
||||
return VoxelShapes.cuboid(new Box(0.0, 0, 0.0, 1.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
|
||||
ShapeContext context) {
|
||||
return VoxelShapes.cuboid(new Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static Function<BlockEntityRenderDispatcher, BlockEntityRenderer<ChargerBlockEntity>> createTesr() {
|
||||
return dispatcher -> new ModularTESR<>(dispatcher, new ItemRenderable<>(ChargerBlock::getRenderedItem));
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static Pair<ItemStack, Transformation> getRenderedItem(ChargerBlockEntity tile) {
|
||||
Transformation transform = new Transformation(new Vector3f(), new Vector3f(0.5f, 0.375f, 0.5f), new Vector3f(1f, 1f, 1f));
|
||||
return new ImmutablePair<>(tile.getInternalInventory().getInvStack(0), transform);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.CondenserContainer;
|
||||
import appeng.tile.misc.CondenserBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CondenserBlock extends AEBaseTileBlock<CondenserBlockEntity> {
|
||||
|
||||
public CondenserBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (player.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
if (Platform.isServer()) {
|
||||
final CondenserBlockEntity tc = this.getBlockEntity(w, pos);
|
||||
if (tc != null && !player.isInSneakingPose()) {
|
||||
ContainerOpener.openContainer(CondenserContainer.TYPE, player,
|
||||
ContainerLocator.forTileEntitySide(tc, hit.getSide()));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.InscriberContainer;
|
||||
import appeng.tile.misc.InscriberBlockEntity;
|
||||
|
||||
public class InscriberBlock extends AEBaseTileBlock<InscriberBlockEntity> {
|
||||
|
||||
public InscriberBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
|
||||
return 2; // FIXME validate this. a) possibly not required because of getShape b) value
|
||||
// range. was 2 in 1.10
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (!p.isInSneakingPose()) {
|
||||
final InscriberBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (!tg.isClient()) {
|
||||
ContainerOpener.openContainer(InscriberContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.TileEntityRendering;
|
||||
import appeng.bootstrap.TileEntityRenderingCustomizer;
|
||||
import appeng.client.render.tesr.InscriberTESR;
|
||||
import appeng.tile.misc.InscriberBlockEntity;
|
||||
|
||||
public class InscriberRendering implements TileEntityRenderingCustomizer<InscriberBlockEntity> {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void customize(TileEntityRendering<InscriberBlockEntity> rendering) {
|
||||
rendering.tileEntityRenderer(InscriberTESR::new);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.InterfaceContainer;
|
||||
import appeng.tile.misc.InterfaceBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class InterfaceBlock extends AEBaseTileBlock<InterfaceBlockEntity> {
|
||||
|
||||
private static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.of("omnidirectional");
|
||||
|
||||
public InterfaceBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(OMNIDIRECTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, InterfaceBlockEntity te) {
|
||||
return currentState.with(OMNIDIRECTIONAL, te.isOmniDirectional());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final InterfaceBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(InterfaceContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCustomRotation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customRotateBlock(final IOrientable rotatable, final Direction axis) {
|
||||
if (rotatable instanceof InterfaceBlockEntity) {
|
||||
((InterfaceBlockEntity) rotatable).setSide(axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.api.util.IOrientableBlock;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.helpers.MetaRotation;
|
||||
import appeng.tile.misc.LightDetectorBlockEntity;
|
||||
|
||||
public class LightDetectorBlock extends AEBaseTileBlock<LightDetectorBlockEntity> implements IOrientableBlock {
|
||||
|
||||
// Used to alternate between two variants of the fixture on adjacent blocks
|
||||
public static final BooleanProperty ODD = BooleanProperty.of("odd");
|
||||
|
||||
public LightDetectorBlock() {
|
||||
super(defaultProps(Material.SUPPORTED));
|
||||
this.setDefaultState(this.getDefaultState().with(Properties.FACING, Direction.UP).with(ODD, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(Properties.FACING);
|
||||
builder.add(ODD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeakRedstonePower(final BlockState state, final BlockView w, final BlockPos pos, final Direction side) {
|
||||
if (w instanceof World && this.getBlockEntity(w, pos).isReady()) {
|
||||
// FIXME: This is ... uhm... fishy
|
||||
return ((World) w).getLightLevel(pos) - 6;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsRedstonePower(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
||||
final Direction up = this.getOrientable(world, pos).getUp();
|
||||
if (!this.canPlaceAt(world, pos, up.getOpposite())) {
|
||||
// FIXME: Double check that this actually updates neighbors
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
final LightDetectorBlockEntity tld = this.getBlockEntity(world, pos);
|
||||
if (tld != null) {
|
||||
tld.updateLight();
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
return this.canPlaceAt(w, pos, up.getOpposite());
|
||||
}
|
||||
|
||||
private boolean canPlaceAt(final BlockView w, final BlockPos pos, final Direction dir) {
|
||||
final BlockPos test = pos.offset(dir);
|
||||
BlockState blockstate = w.getBlockState(test);
|
||||
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
|
||||
// FIXME: We should / rather MUST use state here because at startup, this gets
|
||||
// called without a world
|
||||
|
||||
final Direction up = this.getOrientable(w, pos).getUp();
|
||||
final double xOff = -0.3 * up.getOffsetX();
|
||||
final double yOff = -0.3 * up.getOffsetY();
|
||||
final double zOff = -0.3 * up.getOffsetZ();
|
||||
return VoxelShapes
|
||||
.cuboid(new Box(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
|
||||
ShapeContext context) {
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
|
||||
for (final Direction dir : Direction.values()) {
|
||||
if (this.canPlaceAt(w, pos, dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOrientable getOrientable(final BlockView w, final BlockPos pos) {
|
||||
return new MetaRotation(w, pos, Properties.FACING);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.api.util.IOrientableBlock;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.render.effects.ParticleTypes;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.MetaRotation;
|
||||
|
||||
public class QuartzFixtureBlock extends AEBaseBlock implements IOrientableBlock {
|
||||
|
||||
// Cache VoxelShapes for each facing
|
||||
private static final Map<Direction, VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
SHAPES = new EnumMap<>(Direction.class);
|
||||
|
||||
for (Direction facing : Direction.values()) {
|
||||
final double xOff = -0.3 * facing.getOffsetX();
|
||||
final double yOff = -0.3 * facing.getOffsetY();
|
||||
final double zOff = -0.3 * facing.getOffsetZ();
|
||||
VoxelShape shape = VoxelShapes
|
||||
.cuboid(new Box(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
|
||||
SHAPES.put(facing, shape);
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot use the vanilla FACING property here because it excludes facing DOWN
|
||||
public static final DirectionProperty FACING = Properties.FACING;
|
||||
|
||||
// Used to alternate between two variants of the fixture on adjacent blocks
|
||||
public static final BooleanProperty ODD = BooleanProperty.of("odd");
|
||||
|
||||
public QuartzFixtureBlock() {
|
||||
super(defaultProps(Material.SUPPORTED).noCollision().strength(0).lightLevel(14)
|
||||
.sounds(BlockSoundGroup.GLASS));
|
||||
|
||||
this.setDefaultState(getDefaultState().with(FACING, Direction.UP).with(ODD, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING, ODD);
|
||||
}
|
||||
|
||||
// For reference, see WallTorchBlock
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockState getPlacementState(ItemPlacementContext context) {
|
||||
BlockState blockstate = super.getPlacementState(context);
|
||||
BlockPos pos = context.getBlockPos();
|
||||
|
||||
// Set the even/odd property
|
||||
boolean oddPlacement = ((pos.getX() + pos.getY() + pos.getZ()) % 2) != 0;
|
||||
blockstate = blockstate.with(ODD, oddPlacement);
|
||||
|
||||
WorldView iworldreader = context.getWorld();
|
||||
Direction[] adirection = context.getPlacementDirections();
|
||||
|
||||
for (Direction direction : adirection) {
|
||||
if (canPlaceAt(iworldreader, pos, direction)) {
|
||||
return blockstate.with(FACING, direction.getOpposite());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Break the fixture if the block it is attached to is changed so that it could
|
||||
// no longer be placed
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState facingState, WorldAccess worldIn,
|
||||
BlockPos pos, BlockPos facingPos) {
|
||||
Direction fixtureFacing = state.get(FACING);
|
||||
if (facing.getOpposite() == fixtureFacing && !canPlaceAt(worldIn, pos, facing)) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
// FIXME: I think this entire method -> not required, but not sure... are quartz
|
||||
// fixtures rotateable???
|
||||
return this.canPlaceAt(w, pos, up.getOpposite());
|
||||
}
|
||||
|
||||
private boolean canPlaceAt(final WorldView w, final BlockPos pos, final Direction dir) {
|
||||
final BlockPos test = pos.offset(dir);
|
||||
BlockState blockstate = w.getBlockState(test);
|
||||
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
Direction facing = state.get(FACING);
|
||||
return SHAPES.get(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
|
||||
if (!AEConfig.instance().isEnableEffects()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (r.nextFloat() < 0.98) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Direction up = this.getOrientable(w, pos).getUp();
|
||||
final double xOff = -0.3 * up.getOffsetX();
|
||||
final double yOff = -0.3 * up.getOffsetY();
|
||||
final double zOff = -0.3 * up.getOffsetZ();
|
||||
for (int bolts = 0; bolts < 3; bolts++) {
|
||||
if (AppEng.instance().shouldAddParticles(r)) {
|
||||
w.addParticle(ParticleTypes.LIGHTNING, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(),
|
||||
zOff + 0.5 + pos.getZ(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Replaced by the postPlaceupdate stuff above, but check item drops!
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final Direction up = this.getOrientable(world, pos).getUp();
|
||||
if (!this.canPlaceAt(world, pos, up.getOpposite())) {
|
||||
this.dropTorch(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private void dropTorch(final World w, final BlockPos pos) {
|
||||
final BlockState prev = w.getBlockState(pos);
|
||||
w.breakBlock(pos, true);
|
||||
w.updateListeners(pos, prev, w.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
|
||||
for (final Direction dir : Direction.values()) {
|
||||
if (this.canPlaceAt(w, pos, dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOrientable getOrientable(final BlockView w, final BlockPos pos) {
|
||||
return new MetaRotation(w, pos, FACING);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.util.IOrientableBlock;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.client.render.effects.ParticleTypes;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.tile.misc.QuartzGrowthAcceleratorBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class QuartzGrowthAcceleratorBlock extends AEBaseTileBlock<QuartzGrowthAcceleratorBlockEntity>
|
||||
implements IOrientableBlock {
|
||||
|
||||
private static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
||||
|
||||
public QuartzGrowthAcceleratorBlock() {
|
||||
super(defaultProps(Material.STONE).sounds(BlockSoundGroup.METAL));
|
||||
this.setDefaultState(this.getDefaultState().with(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, QuartzGrowthAcceleratorBlockEntity te) {
|
||||
return currentState.with(POWERED, te.isPowered());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(POWERED);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
|
||||
if (!AEConfig.instance().isEnableEffects()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final QuartzGrowthAcceleratorBlockEntity cga = this.getBlockEntity(w, pos);
|
||||
|
||||
if (cga != null && cga.isPowered() && AppEng.instance().shouldAddParticles(r)) {
|
||||
final double d0 = r.nextFloat() - 0.5F;
|
||||
final double d1 = r.nextFloat() - 0.5F;
|
||||
|
||||
final Direction up = cga.getUp();
|
||||
final Direction forward = cga.getForward();
|
||||
final Direction west = Platform.crossProduct(forward, up);
|
||||
|
||||
double rx = 0.5 + pos.getX();
|
||||
double ry = 0.5 + pos.getY();
|
||||
double rz = 0.5 + pos.getZ();
|
||||
|
||||
rx += up.getOffsetX() * d0;
|
||||
ry += up.getOffsetY() * d0;
|
||||
rz += up.getOffsetZ() * d0;
|
||||
|
||||
final int x = pos.getX();
|
||||
final int y = pos.getY();
|
||||
final int z = pos.getZ();
|
||||
|
||||
double dz = 0;
|
||||
double dx = 0;
|
||||
BlockPos pt = null;
|
||||
|
||||
switch (r.nextInt(4)) {
|
||||
case 0:
|
||||
dx = 0.6;
|
||||
dz = d1;
|
||||
pt = new BlockPos(x + west.getOffsetX(), y + west.getOffsetY(), z + west.getOffsetZ());
|
||||
|
||||
break;
|
||||
case 1:
|
||||
dx = d1;
|
||||
dz += 0.6;
|
||||
pt = new BlockPos(x + forward.getOffsetX(), y + forward.getOffsetY(), z + forward.getOffsetZ());
|
||||
|
||||
break;
|
||||
case 2:
|
||||
dx = d1;
|
||||
dz = -0.6;
|
||||
pt = new BlockPos(x - forward.getOffsetX(), y - forward.getOffsetY(), z - forward.getOffsetZ());
|
||||
|
||||
break;
|
||||
case 3:
|
||||
dx = -0.6;
|
||||
dz = d1;
|
||||
pt = new BlockPos(x - west.getOffsetX(), y - west.getOffsetY(), z - west.getOffsetZ());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!w.getBlockState(pt).isAir()) {
|
||||
return;
|
||||
}
|
||||
|
||||
rx += dx * west.getOffsetX();
|
||||
ry += dx * west.getOffsetY();
|
||||
rz += dx * west.getOffsetZ();
|
||||
|
||||
rx += dz * forward.getOffsetX();
|
||||
ry += dz * forward.getOffsetY();
|
||||
rz += dz * forward.getOffsetZ();
|
||||
|
||||
MinecraftClient.getInstance().particleManager.addParticle(ParticleTypes.LIGHTNING, rx, ry, rz, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.SecurityStationContainer;
|
||||
import appeng.tile.misc.SecurityStationBlockEntity;
|
||||
|
||||
public class SecurityStationBlock extends AEBaseTileBlock<SecurityStationBlockEntity> {
|
||||
|
||||
private static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
||||
|
||||
public SecurityStationBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
|
||||
this.setDefaultState(this.getDefaultState().with(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(POWERED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, SecurityStationBlockEntity te) {
|
||||
return currentState.with(POWERED, te.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final SecurityStationBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (w.isClient()) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
ContainerOpener.openContainer(SecurityStationContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.misc.SkyCompassBlockEntity;
|
||||
|
||||
public class SkyCompassBlock extends AEBaseTileBlock<SkyCompassBlockEntity> {
|
||||
|
||||
public SkyCompassBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
final SkyCompassBlockEntity sc = this.getBlockEntity(w, pos);
|
||||
if (sc != null) {
|
||||
return false;
|
||||
}
|
||||
return this.canPlaceAt(w, pos, forward.getOpposite());
|
||||
}
|
||||
|
||||
private boolean canPlaceAt(final BlockView w, final BlockPos pos, final Direction dir) {
|
||||
final BlockPos test = pos.offset(dir);
|
||||
BlockState blockstate = w.getBlockState(test);
|
||||
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final SkyCompassBlockEntity sc = this.getBlockEntity(world, pos);
|
||||
final Direction forward = sc.getForward();
|
||||
if (!this.canPlaceAt(world, pos, forward.getOpposite())) {
|
||||
this.dropTorch(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private void dropTorch(final World w, final BlockPos pos) {
|
||||
final BlockState prev = w.getBlockState(pos);
|
||||
w.breakBlock(pos, true);
|
||||
w.updateListeners(pos, prev, w.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
|
||||
for (final Direction dir : Direction.values()) {
|
||||
if (this.canPlaceAt(w, pos, dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
|
||||
// TODO: This definitely needs to be memoized
|
||||
|
||||
final SkyCompassBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
final Direction forward = tile.getForward();
|
||||
|
||||
double minX = 0;
|
||||
double minY = 0;
|
||||
double minZ = 0;
|
||||
double maxX = 1;
|
||||
double maxY = 1;
|
||||
double maxZ = 1;
|
||||
|
||||
switch (forward) {
|
||||
case DOWN:
|
||||
minZ = minX = 5.0 / 16.0;
|
||||
maxZ = maxX = 11.0 / 16.0;
|
||||
maxY = 1.0;
|
||||
minY = 14.0 / 16.0;
|
||||
break;
|
||||
case EAST:
|
||||
minZ = minY = 5.0 / 16.0;
|
||||
maxZ = maxY = 11.0 / 16.0;
|
||||
maxX = 2.0 / 16.0;
|
||||
minX = 0.0;
|
||||
break;
|
||||
case NORTH:
|
||||
minY = minX = 5.0 / 16.0;
|
||||
maxY = maxX = 11.0 / 16.0;
|
||||
maxZ = 1.0;
|
||||
minZ = 14.0 / 16.0;
|
||||
break;
|
||||
case SOUTH:
|
||||
minY = minX = 5.0 / 16.0;
|
||||
maxY = maxX = 11.0 / 16.0;
|
||||
maxZ = 2.0 / 16.0;
|
||||
minZ = 0.0;
|
||||
break;
|
||||
case UP:
|
||||
minZ = minX = 5.0 / 16.0;
|
||||
maxZ = maxX = 11.0 / 16.0;
|
||||
maxY = 2.0 / 16.0;
|
||||
minY = 0.0;
|
||||
break;
|
||||
case WEST:
|
||||
minZ = minY = 5.0 / 16.0;
|
||||
maxZ = maxY = 11.0 / 16.0;
|
||||
maxX = 1.0;
|
||||
minX = 14.0 / 16.0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return VoxelShapes.cuboid(new Box(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
}
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
|
||||
ShapeContext context) {
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -16,22 +16,22 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
package appeng.block.misc;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.container.implementations.MEPortableCellContainer;
|
||||
import appeng.bootstrap.TileEntityRendering;
|
||||
import appeng.bootstrap.TileEntityRenderingCustomizer;
|
||||
import appeng.client.render.tesr.SkyCompassTESR;
|
||||
import appeng.tile.misc.SkyCompassBlockEntity;
|
||||
|
||||
public class MEPortableCellScreen extends MEMonitorableScreen<MEPortableCellContainer> {
|
||||
|
||||
public MEPortableCellScreen(MEPortableCellContainer container, PlayerInventory playerInventory,
|
||||
Text title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
public class SkyCompassRendering implements TileEntityRenderingCustomizer<SkyCompassBlockEntity> {
|
||||
|
||||
@Override
|
||||
int getMaxRows() {
|
||||
return 3;
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(TileEntityRendering<SkyCompassBlockEntity> rendering) {
|
||||
rendering.tileEntityRenderer(SkyCompassTESR::new);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.PersistentProjectileEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.entity.TinyTNTPrimedEntity;
|
||||
|
||||
public class TinyTNTBlock extends AEBaseBlock {
|
||||
|
||||
private static final VoxelShape SHAPE = VoxelShapes
|
||||
.cuboid(new Box(0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f));
|
||||
|
||||
public TinyTNTBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
|
||||
return 2; // FIXME: Validate that this is the correct value range
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World w, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
final BlockHitResult hit) {
|
||||
ItemStack heldItem = player.getStackInHand(hand);
|
||||
if (heldItem.getItem() == Items.FLINT_AND_STEEL) {
|
||||
this.startFuse(w, pos, player);
|
||||
w.removeBlock(pos, false);
|
||||
heldItem.damage(1, player, p -> {
|
||||
p.sendToolBreakStatus(hand);
|
||||
}); // FIXME Check if onBroken is equivalent
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
return super.onUse(state, w, pos, player, hand, hit);
|
||||
}
|
||||
}
|
||||
|
||||
public void startFuse(final World w, final BlockPos pos, final LivingEntity igniter) {
|
||||
if (!w.isClient) {
|
||||
final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(w, pos.getX() + 0.5F,
|
||||
pos.getY(), pos.getZ() + 0.5F, igniter);
|
||||
w.spawnEntity(primedTinyTNTEntity);
|
||||
w.playSound(null, primedTinyTNTEntity.getX(), primedTinyTNTEntity.getY(),
|
||||
primedTinyTNTEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
||||
if (world.isReceivingRedstonePower(pos)) {
|
||||
this.startFuse(world, pos, null);
|
||||
world.removeBlock(pos, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(BlockState state, World w, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||
super.onBlockAdded(state, w, pos, oldState, isMoving);
|
||||
|
||||
if (w.getReceivedStrongRedstonePower(pos) > 0) {
|
||||
this.startFuse(w, pos, null);
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSteppedOn(final World w, final BlockPos pos, final Entity entity) {
|
||||
if (entity instanceof PersistentProjectileEntity && !w.isClient) {
|
||||
final PersistentProjectileEntity entityarrow = (PersistentProjectileEntity) entity;
|
||||
|
||||
if (entityarrow.isOnFire()) {
|
||||
LivingEntity igniter = null;
|
||||
// Check if the shooter still exists
|
||||
Entity shooter = entityarrow.getOwner();
|
||||
if (shooter instanceof LivingEntity) {
|
||||
igniter = (LivingEntity) shooter;
|
||||
}
|
||||
this.startFuse(w, pos, igniter);
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDropItemsOnExplosion(final Explosion exp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyedByExplosion(final World w, final BlockPos pos, final Explosion exp) {
|
||||
super.onDestroyedByExplosion(w, pos, exp);
|
||||
if (!w.isClient) {
|
||||
final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(w, pos.getX() + 0.5F,
|
||||
pos.getY() + 0.5F, pos.getZ() + 0.5F, exp.getCausingEntity());
|
||||
primedTinyTNTEntity
|
||||
.setFuse(w.random.nextInt(primedTinyTNTEntity.getFuse() / 4) + primedTinyTNTEntity.getFuse() / 8);
|
||||
w.spawnEntity(primedTinyTNTEntity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.misc;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.VibrationChamberContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.tile.misc.VibrationChamberBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class VibrationChamberBlock extends AEBaseTileBlock<VibrationChamberBlockEntity> {
|
||||
|
||||
// Indicates that the vibration chamber is currently working
|
||||
private static final BooleanProperty ACTIVE = BooleanProperty.of("active");
|
||||
|
||||
public VibrationChamberBlock() {
|
||||
super(defaultProps(Material.METAL).strength(4.2F));
|
||||
this.setDefaultState(this.getDefaultState().with(ACTIVE, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, VibrationChamberBlockEntity te) {
|
||||
return currentState.with(ACTIVE, te.isOn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(ACTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (player.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
if (Platform.isServer()) {
|
||||
final VibrationChamberBlockEntity tc = this.getBlockEntity(w, pos);
|
||||
if (tc != null && !player.isInSneakingPose()) {
|
||||
ContainerOpener.openContainer(VibrationChamberContainer.TYPE, player,
|
||||
ContainerLocator.forTileEntitySide(tc, hit.getSide()));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
|
||||
if (!AEConfig.instance().isEnableEffects()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final VibrationChamberBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null && tile.isOn) {
|
||||
double f1 = pos.getX() + 0.5F;
|
||||
double f2 = pos.getY() + 0.5F;
|
||||
double f3 = pos.getZ() + 0.5F;
|
||||
|
||||
final Direction forward = tile.getForward();
|
||||
final Direction up = tile.getUp();
|
||||
|
||||
final int west_x = forward.getOffsetY() * up.getOffsetZ() - forward.getOffsetZ() * up.getOffsetY();
|
||||
final int west_y = forward.getOffsetZ() * up.getOffsetX() - forward.getOffsetX() * up.getOffsetZ();
|
||||
final int west_z = forward.getOffsetX() * up.getOffsetY() - forward.getOffsetY() * up.getOffsetX();
|
||||
|
||||
f1 += forward.getOffsetX() * 0.6;
|
||||
f2 += forward.getOffsetY() * 0.6;
|
||||
f3 += forward.getOffsetZ() * 0.6;
|
||||
|
||||
final double ox = r.nextDouble();
|
||||
final double oy = r.nextDouble() * 0.2f;
|
||||
|
||||
f1 += up.getOffsetX() * (-0.3 + oy);
|
||||
f2 += up.getOffsetY() * (-0.3 + oy);
|
||||
f3 += up.getOffsetZ() * (-0.3 + oy);
|
||||
|
||||
f1 += west_x * (0.3 * ox - 0.15);
|
||||
f2 += west_y * (0.3 * ox - 0.15);
|
||||
f3 += west_z * (0.3 * ox - 0.15);
|
||||
|
||||
w.addParticle(ParticleTypes.SMOKE, f1, f2, f3, 0.0D, 0.0D, 0.0D);
|
||||
w.addParticle(ParticleTypes.FLAME, f1, f2, f3, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import appeng.api.parts.IFacadeContainer;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.client.render.cablebus.CableBusBakedModel;
|
||||
import appeng.client.render.cablebus.CableBusBreakingParticle;
|
||||
import appeng.client.render.cablebus.CableBusRenderState;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.integration.abstraction.IAEFacade;
|
||||
import appeng.parts.ICableBusContainer;
|
||||
import appeng.parts.NullCableBusContainer;
|
||||
import appeng.tile.networking.CableBusBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockGatherCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.particle.ParticleManager;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.hit.HitResult.Type;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implements IAEFacade {
|
||||
|
||||
private static final ICableBusContainer NULL_CABLE_BUS = new NullCableBusContainer();
|
||||
|
||||
public CableBusBlock() {
|
||||
super(defaultProps(AEGlassMaterial.INSTANCE)
|
||||
.nonOpaque()
|
||||
.dropsNothing()
|
||||
.dynamicBounds());
|
||||
}
|
||||
|
||||
static {
|
||||
ClientPickBlockGatherCallback.EVENT.register((player, result) -> {
|
||||
if (result instanceof BlockHitResult) {
|
||||
BlockHitResult blockResult = (BlockHitResult) result;
|
||||
BlockState blockState = player.world.getBlockState(((BlockHitResult) result).getBlockPos());
|
||||
if (blockState.getBlock() instanceof CableBusBlock) {
|
||||
CableBusBlock cableBus = (CableBusBlock) blockState.getBlock();
|
||||
return cableBus.getPickBlock(blockState,
|
||||
result, player.world, blockResult.getBlockPos(), player);
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTranslucent(BlockState state, BlockView reader, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(final BlockState state, final World worldIn, final BlockPos pos, final Random rand) {
|
||||
this.cb(worldIn, pos).randomDisplayTick(worldIn, pos, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeakRedstonePower(final BlockState state, final BlockView w, final BlockPos pos, final Direction side) {
|
||||
return this.cb(w, pos).isProvidingWeakPower(side.getOpposite()); // TODO:
|
||||
// IS
|
||||
// OPPOSITE!?
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsRedstonePower(final BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entityIn) {
|
||||
this.cb(w, pos).onEntityCollision(entityIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
|
||||
return this.cb(world, pos).isProvidingStrongPower(direction.getOpposite()); // TODO:
|
||||
// IS
|
||||
// OPPOSITE!?
|
||||
}
|
||||
|
||||
// FIXME Dynamic light seems unsupported (?) Must maybe use blockstates... :|
|
||||
// FIXME FABRIC @Override
|
||||
// FIXME FABRIC public int getLightValue(final BlockState state, final BlockView world, final BlockPos pos) {
|
||||
// FIXME FABRIC if (state.getBlock() != this) {
|
||||
// FIXME FABRIC return state.getLuminance();
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC return this.cb(world, pos).getLightValue();
|
||||
// FIXME FABRIC }
|
||||
|
||||
|
||||
// FIXME: Must hook isClimbing ourselves
|
||||
// FIXME FABRIC @Override
|
||||
// FIXME FABRIC public boolean isLadder(BlockState state, WorldView world, BlockPos pos, LivingEntity entity) {
|
||||
// FIXME FABRIC return this.cb(world, pos).isLadder(entity);
|
||||
// FIXME FABRIC }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canReplace(BlockState state, ItemPlacementContext context) {
|
||||
// FIXME: Potentially check the fluid one too
|
||||
return super.canReplace(state, context) && this.cb(context.getWorld(), context.getBlockPos()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
// FIXME FABRIC Hook does not exist
|
||||
// FIXME FABRIC @Override
|
||||
// FIXME FABRIC public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player,
|
||||
// FIXME FABRIC boolean willHarvest, IFluidState fluid) {
|
||||
// FIXME FABRIC if (player.abilities.isCreativeMode) {
|
||||
// FIXME FABRIC final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
// FIXME FABRIC if (tile != null) {
|
||||
// FIXME FABRIC tile.disableDrops();
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC // maybe ray trace?
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC return super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
|
||||
// FIXME FABRIC }
|
||||
|
||||
// FIXME FABRIC @Override
|
||||
// FIXME FABRIC public boolean canConnectRedstone(final BlockState state, final BlockView w, final BlockPos pos,
|
||||
// FIXME FABRIC Direction side) {
|
||||
// FIXME FABRIC if (side == null) {
|
||||
// FIXME FABRIC side = Direction.UP;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC return this.cb(w, pos).canConnectRedstone(EnumSet.of(side));
|
||||
// FIXME FABRIC }
|
||||
|
||||
public ItemStack getPickBlock(BlockState state, HitResult target, BlockView world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
final Vec3d v3 = target.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
|
||||
final SelectedPart sp = this.cb(world, pos).selectPart(v3);
|
||||
|
||||
if (sp.part != null) {
|
||||
return sp.part.getItemStack(PartItemStack.PICK);
|
||||
} else if (sp.facade != null) {
|
||||
return sp.facade.getItemStack();
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
// FIXME FABRIC MIXIN net.minecraft.client.particle.ParticleManager.addBlockBreakingParticles
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean addHitEffects(final BlockState state, final World world, final HitResult target,
|
||||
final ParticleManager effectRenderer) {
|
||||
|
||||
// Half the particle rate. Since we're spawning concentrated on a specific spot,
|
||||
// our particle effect otherwise looks too strong
|
||||
if (Platform.getRandom().nextBoolean()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target.getType() != Type.BLOCK) {
|
||||
return false;
|
||||
}
|
||||
BlockPos blockPos = new BlockPos(target.getPos().x, target.getPos().y, target.getPos().z);
|
||||
|
||||
ICableBusContainer cb = this.cb(world, blockPos);
|
||||
|
||||
// Our built-in model has the actual baked sprites we need
|
||||
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager()
|
||||
.getModel(this.getDefaultState());
|
||||
|
||||
// We cannot add the effect if we don't have the model
|
||||
if (!(model instanceof CableBusBakedModel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CableBusBakedModel cableBusModel = (CableBusBakedModel) model;
|
||||
|
||||
CableBusRenderState renderState = cb.getRenderState();
|
||||
|
||||
// Spawn a particle for one of the particle textures
|
||||
Sprite texture = Platform.pickRandom(cableBusModel.getParticleTextures(renderState));
|
||||
if (texture != null) {
|
||||
double x = target.getPos().x;
|
||||
double y = target.getPos().y;
|
||||
double z = target.getPos().z;
|
||||
// FIXME: Check how this looks, probably like shit, maybe provide parts the
|
||||
// ability to supply particle textures???
|
||||
effectRenderer
|
||||
.addParticle(new CableBusBreakingParticle((ClientWorld) world, x, y, z, texture).scale(0.8F));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// FIXME FABRIC: Mixin to net.minecraft.client.particle.ParticleManager.addBlockBreakParticles
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean addDestroyEffects(BlockState state, World world, BlockPos pos, ParticleManager effectRenderer) {
|
||||
ICableBusContainer cb = this.cb(world, pos);
|
||||
|
||||
// Our built-in model has the actual baked sprites we need
|
||||
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager()
|
||||
.getModel(this.getDefaultState());
|
||||
|
||||
// We cannot add the effect if we dont have the model
|
||||
if (!(model instanceof CableBusBakedModel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CableBusBakedModel cableBusModel = (CableBusBakedModel) model;
|
||||
|
||||
CableBusRenderState renderState = cb.getRenderState();
|
||||
|
||||
List<Sprite> textures = cableBusModel.getParticleTextures(renderState);
|
||||
|
||||
if (!textures.isEmpty()) {
|
||||
// Shamelessly inspired by ParticleManager.addBlockDestroyEffects
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
for (int l = 0; l < 4; ++l) {
|
||||
// Randomly select one of the textures if the cable bus has more than just one
|
||||
// possibility here
|
||||
final Sprite texture = Platform.pickRandom(textures);
|
||||
|
||||
final double x = pos.getX() + (j + 0.5D) / 4.0D;
|
||||
final double y = pos.getY() + (k + 0.5D) / 4.0D;
|
||||
final double z = pos.getZ() + (l + 0.5D) / 4.0D;
|
||||
|
||||
// FIXME: Check how this looks, probably like shit, maybe provide parts the
|
||||
// ability to supply particle textures???
|
||||
Particle effect = new CableBusBreakingParticle((ClientWorld) world, x, y, z, x - pos.getX() - 0.5D,
|
||||
y - pos.getY() - 0.5D, z - pos.getZ() - 0.5D, texture);
|
||||
effectRenderer.addParticle(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
if (Platform.isServer()) {
|
||||
this.cb(world, pos).onneighborUpdate(world, pos, fromPos);
|
||||
}
|
||||
}
|
||||
|
||||
private ICableBusContainer cb(final BlockView w, final BlockPos pos) {
|
||||
final BlockEntity te = w.getBlockEntity(pos);
|
||||
ICableBusContainer out = null;
|
||||
|
||||
if (te instanceof CableBusBlockEntity) {
|
||||
out = ((CableBusBlockEntity) te).getCableBus();
|
||||
}
|
||||
|
||||
return out == null ? NULL_CABLE_BUS : out;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IFacadeContainer fc(final BlockView w, final BlockPos pos) {
|
||||
final BlockEntity te = w.getBlockEntity(pos);
|
||||
IFacadeContainer out = null;
|
||||
|
||||
if (te instanceof CableBusBlockEntity) {
|
||||
out = ((CableBusBlockEntity) te).getCableBus().getFacadeContainer();
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void onBlockBreakStart(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
|
||||
if (worldIn.isClient()) {
|
||||
final HitResult rtr = AppEng.instance().getRTR();
|
||||
if (rtr instanceof BlockHitResult) {
|
||||
BlockHitResult brtr = (BlockHitResult) rtr;
|
||||
if (brtr.getBlockPos().equals(pos)) {
|
||||
final Vec3d hitVec = rtr.getPos().subtract(new Vec3d(pos.getX(), pos.getY(), pos.getZ()));
|
||||
|
||||
if (this.cb(worldIn, pos).clicked(player, Hand.MAIN_HAND, hitVec)) {
|
||||
throw new IllegalStateException();
|
||||
// FIXME FABRIC NetworkHandler.instance().sendToServer(new ClickPacket(pos, brtr.getSide(), (float) hitVec.x,
|
||||
// FIXME FABRIC (float) hitVec.y, (float) hitVec.z, Hand.MAIN_HAND, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onBlockClickPacket(World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, Vec3d hitVec) {
|
||||
this.cb(worldIn, pos).clicked(playerIn, hand, hitVec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
// Transform from world into block space
|
||||
Vec3d hitVec = hit.getPos();
|
||||
Vec3d hitInBlock = new Vec3d(hitVec.x - pos.getX(), hitVec.y - pos.getY(), hitVec.z - pos.getZ());
|
||||
return this.cb(w, pos).activate(player, hand, hitInBlock) ? ActionResult.SUCCESS : ActionResult.PASS;
|
||||
}
|
||||
|
||||
public boolean recolorBlock(final BlockView world, final BlockPos pos, final Direction side,
|
||||
final DyeColor color, final PlayerEntity who) {
|
||||
try {
|
||||
return this.cb(world, pos).recolourBlock(side, AEColor.values()[color.ordinal()], who);
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getFacadeState(BlockView world, BlockPos pos, Direction side) {
|
||||
if (side != null) {
|
||||
IFacadeContainer container = this.fc(world, pos);
|
||||
if (container != null) {
|
||||
IFacadePart facade = container.getFacade(AEPartLocation.fromFacing(side));
|
||||
if (facade != null) {
|
||||
return facade.getBlockState();
|
||||
}
|
||||
}
|
||||
}
|
||||
return world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
CableBusBlockEntity te = getBlockEntity(w, pos);
|
||||
if (te == null) {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
return te.getCableBus().getOutlineShape();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
CableBusBlockEntity te = getBlockEntity(w, pos);
|
||||
if (te == null) {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
Entity entity = null;
|
||||
// FIXME FABRIC: even EntityShapeContext doesn't give us the actual entity we're colliding with :|
|
||||
return te.getCableBus().getCollisionShape(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+18
-12
@@ -16,7 +16,7 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render;
|
||||
package appeng.block.networking;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -25,28 +25,34 @@ import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.parts.CableBusContainer;
|
||||
import appeng.tile.networking.CableBusBlockEntity;
|
||||
|
||||
/**
|
||||
* Automatically exposes the color of a colorable tile using tint indices 0-2
|
||||
* Exposes the cable bus color as tint indices 0 (dark variant), 1 (medium
|
||||
* variant) and 2 (bright variant).
|
||||
*/
|
||||
public class ColorableTileBlockColor implements BlockColorProvider {
|
||||
|
||||
public static final ColorableTileBlockColor INSTANCE = new ColorableTileBlockColor();
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class CableBusColor implements BlockColorProvider {
|
||||
|
||||
@Override
|
||||
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int tintIndex) {
|
||||
AEColor color = AEColor.TRANSPARENT; // Default to a neutral color
|
||||
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int color) {
|
||||
|
||||
AEColor busColor = AEColor.TRANSPARENT;
|
||||
|
||||
if (worldIn != null && pos != null) {
|
||||
BlockEntity te = worldIn.getBlockEntity(pos);
|
||||
if (te instanceof IColorableTile) {
|
||||
color = ((IColorableTile) te).getColor();
|
||||
BlockEntity tileEntity = worldIn.getBlockEntity(pos);
|
||||
if (tileEntity instanceof CableBusBlockEntity) {
|
||||
CableBusContainer container = ((CableBusBlockEntity) tileEntity).getCableBus();
|
||||
busColor = container.getColor();
|
||||
}
|
||||
}
|
||||
|
||||
return color.getVariantByTintIndex(tintIndex);
|
||||
return busColor.getVariantByTintIndex(color);
|
||||
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -16,25 +16,28 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.crafting;
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
/**
|
||||
* Rendering customization for the crafting cube.
|
||||
* Customizes the rendering behavior for cable busses, which are the biggest
|
||||
* multipart of AE2.
|
||||
*/
|
||||
public class CraftingCubeRendering extends BlockRenderingCustomizer {
|
||||
public class CableBusRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
// Disable auto-rotation
|
||||
// FIXME This is straight up impossible in Vanilla, and questionable if it's actually needed.
|
||||
// FIXME rendering.renderType(rt -> true);
|
||||
|
||||
rendering.blockColor(new CableBusColor());
|
||||
rendering.modelCustomizer((loc, model) -> model);
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.networking.ControllerBlockEntity;
|
||||
|
||||
public class ControllerBlock extends AEBaseTileBlock<ControllerBlockEntity> {
|
||||
|
||||
public enum ControllerBlockState implements StringIdentifiable {
|
||||
offline, online, conflicted;
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls the rendering of the controller block (connected texture style).
|
||||
* inside_a and inside_b are alternating patterns for a controller that is
|
||||
* enclosed by other controllers, and since they are always offline, they do not
|
||||
* have the usual sub-states.
|
||||
*/
|
||||
public enum ControllerRenderType implements StringIdentifiable {
|
||||
block, column_x, column_y, column_z, inside_a, inside_b;
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final EnumProperty<ControllerBlockState> CONTROLLER_STATE = EnumProperty.create("state",
|
||||
ControllerBlockState.class);
|
||||
|
||||
public static final EnumProperty<ControllerRenderType> CONTROLLER_TYPE = EnumProperty.create("type",
|
||||
ControllerRenderType.class);
|
||||
|
||||
public ControllerBlock() {
|
||||
super(defaultProps(Material.METAL).strength(6));
|
||||
this.setDefaultState(this.getDefaultState().with(CONTROLLER_STATE, ControllerBlockState.offline)
|
||||
.with(CONTROLLER_TYPE, ControllerRenderType.block));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(CONTROLLER_STATE);
|
||||
builder.add(CONTROLLER_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will compute the AE_BLOCK_FORWARD, AE_BLOCK_UP and CONTROLLER_TYPE block
|
||||
* states based on adjacent controllers and the network state of this controller
|
||||
* (offline, online, conflicted). This is used to get a rudimentary connected
|
||||
* texture feel for the controller based on how it is placed.
|
||||
*/
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState facingState, WorldAccess world,
|
||||
BlockPos pos, BlockPos facingPos) {
|
||||
|
||||
// FIXME: this might work, or might _NOT_ work, but needs to be investigated
|
||||
|
||||
// Only used for columns, really
|
||||
ControllerRenderType type = ControllerRenderType.block;
|
||||
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
|
||||
// Detect whether controllers are on both sides of the x, y, and z axes
|
||||
final boolean xx = this.getBlockEntity(world, x - 1, y, z) != null
|
||||
&& this.getBlockEntity(world, x + 1, y, z) != null;
|
||||
final boolean yy = this.getBlockEntity(world, x, y - 1, z) != null
|
||||
&& this.getBlockEntity(world, x, y + 1, z) != null;
|
||||
final boolean zz = this.getBlockEntity(world, x, y, z - 1) != null
|
||||
&& this.getBlockEntity(world, x, y, z + 1) != null;
|
||||
|
||||
if (xx && !yy && !zz) {
|
||||
type = ControllerRenderType.column_x;
|
||||
} else if (!xx && yy && !zz) {
|
||||
type = ControllerRenderType.column_y;
|
||||
} else if (!xx && !yy && zz) {
|
||||
type = ControllerRenderType.column_z;
|
||||
} else if ((xx ? 1 : 0) + (yy ? 1 : 0) + (zz ? 1 : 0) >= 2) {
|
||||
final int v = (Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2;
|
||||
|
||||
// While i'd like this to be based on the blockstate randomization feature, this
|
||||
// generates
|
||||
// an alternating pattern based on world position, so this is not 100% doable
|
||||
// with blockstates.
|
||||
if (v == 0) {
|
||||
type = ControllerRenderType.inside_a;
|
||||
} else {
|
||||
type = ControllerRenderType.inside_b;
|
||||
}
|
||||
}
|
||||
|
||||
return state.with(CONTROLLER_TYPE, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final ControllerBlockEntity tc = this.getBlockEntity(world, pos);
|
||||
if (tc != null) {
|
||||
tc.onNeighborChange(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.networking.CreativeEnergyCellBlockEntity;
|
||||
|
||||
public class CreativeEnergyCellBlock extends AEBaseTileBlock<CreativeEnergyCellBlockEntity> {
|
||||
|
||||
public CreativeEnergyCellBlock() {
|
||||
super(defaultProps(AEGlassMaterial.INSTANCE));
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.networking.EnergyAcceptorBlockEntity;
|
||||
|
||||
public class EnergyAcceptorBlock extends AEBaseTileBlock<EnergyAcceptorBlockEntity> {
|
||||
|
||||
public EnergyAcceptorBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.state.IntegerProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.networking.EnergyCellBlockEntity;
|
||||
|
||||
public class EnergyCellBlock extends AEBaseTileBlock<EnergyCellBlockEntity> {
|
||||
|
||||
public static final IntegerProperty ENERGY_STORAGE = IntegerProperty.create("fullness", 0, 7);
|
||||
|
||||
public EnergyCellBlock() {
|
||||
super(defaultProps(AEGlassMaterial.INSTANCE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemStacks) {
|
||||
super.appendStacks(group, itemStacks);
|
||||
|
||||
final ItemStack charged = new ItemStack(this, 1);
|
||||
final CompoundTag tag = charged.getOrCreateTag();
|
||||
tag.putDouble("internalCurrentPower", this.getMaxPower());
|
||||
tag.putDouble("internalMaxPower", this.getMaxPower());
|
||||
|
||||
itemStacks.add(charged);
|
||||
}
|
||||
|
||||
public double getMaxPower() {
|
||||
return 200000.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(ENERGY_STORAGE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.WirelessContainer;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.networking.WirelessBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class WirelessBlock extends AEBaseTileBlock<WirelessBlockEntity> {
|
||||
|
||||
enum State implements StringIdentifiable {
|
||||
OFF, ON, HAS_CHANNEL;
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static final EnumProperty<State> STATE = EnumProperty.create("state", State.class);
|
||||
|
||||
public WirelessBlock() {
|
||||
super(defaultProps(AEGlassMaterial.INSTANCE)
|
||||
.nonOpaque()
|
||||
.solidBlock((state, world, pos) -> false)
|
||||
);
|
||||
this.setDefaultState(this.getDefaultState().with(STATE, State.OFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, WirelessBlockEntity te) {
|
||||
State teState = State.OFF;
|
||||
|
||||
if (te.isActive()) {
|
||||
teState = State.HAS_CHANNEL;
|
||||
} else if (te.isPowered()) {
|
||||
teState = State.ON;
|
||||
}
|
||||
|
||||
return currentState.with(STATE, teState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World w, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
final WirelessBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
|
||||
if (tg != null && !player.isInSneakingPose()) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(WirelessContainer.TYPE, player,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return super.onUse(state, w, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
final WirelessBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
final Direction forward = tile.getForward();
|
||||
|
||||
double minX = 0;
|
||||
double minY = 0;
|
||||
double minZ = 0;
|
||||
double maxX = 1;
|
||||
double maxY = 1;
|
||||
double maxZ = 1;
|
||||
|
||||
switch (forward) {
|
||||
case DOWN:
|
||||
minZ = minX = 3.0 / 16.0;
|
||||
maxZ = maxX = 13.0 / 16.0;
|
||||
maxY = 1.0;
|
||||
minY = 5.0 / 16.0;
|
||||
break;
|
||||
case EAST:
|
||||
minZ = minY = 3.0 / 16.0;
|
||||
maxZ = maxY = 13.0 / 16.0;
|
||||
maxX = 11.0 / 16.0;
|
||||
minX = 0.0;
|
||||
break;
|
||||
case NORTH:
|
||||
minY = minX = 3.0 / 16.0;
|
||||
maxY = maxX = 13.0 / 16.0;
|
||||
maxZ = 1.0;
|
||||
minZ = 5.0 / 16.0;
|
||||
break;
|
||||
case SOUTH:
|
||||
minY = minX = 3.0 / 16.0;
|
||||
maxY = maxX = 13.0 / 16.0;
|
||||
maxZ = 11.0 / 16.0;
|
||||
minZ = 0.0;
|
||||
break;
|
||||
case UP:
|
||||
minZ = minX = 3.0 / 16.0;
|
||||
maxZ = maxX = 13.0 / 16.0;
|
||||
maxY = 11.0 / 16.0;
|
||||
minY = 0.0;
|
||||
break;
|
||||
case WEST:
|
||||
minZ = minY = 3.0 / 16.0;
|
||||
maxZ = maxY = 13.0 / 16.0;
|
||||
maxX = 1.0;
|
||||
minX = 5.0 / 16.0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return VoxelShapes.cuboid(new Box(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
}
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
|
||||
final WirelessBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
final Direction forward = tile.getForward();
|
||||
|
||||
double minX = 0;
|
||||
double minY = 0;
|
||||
double minZ = 0;
|
||||
double maxX = 1;
|
||||
double maxY = 1;
|
||||
double maxZ = 1;
|
||||
|
||||
switch (forward) {
|
||||
case DOWN:
|
||||
minZ = minX = 3.0 / 16.0;
|
||||
maxZ = maxX = 13.0 / 16.0;
|
||||
maxY = 1.0;
|
||||
minY = 5.0 / 16.0;
|
||||
break;
|
||||
case EAST:
|
||||
minZ = minY = 3.0 / 16.0;
|
||||
maxZ = maxY = 13.0 / 16.0;
|
||||
maxX = 11.0 / 16.0;
|
||||
minX = 0.0;
|
||||
break;
|
||||
case NORTH:
|
||||
minY = minX = 3.0 / 16.0;
|
||||
maxY = maxX = 13.0 / 16.0;
|
||||
maxZ = 1.0;
|
||||
minZ = 5.0 / 16.0;
|
||||
break;
|
||||
case SOUTH:
|
||||
minY = minX = 3.0 / 16.0;
|
||||
maxY = maxX = 13.0 / 16.0;
|
||||
maxZ = 11.0 / 16.0;
|
||||
minZ = 0.0;
|
||||
break;
|
||||
case UP:
|
||||
minZ = minX = 3.0 / 16.0;
|
||||
maxZ = maxX = 13.0 / 16.0;
|
||||
maxY = 11.0 / 16.0;
|
||||
minY = 0.0;
|
||||
break;
|
||||
case WEST:
|
||||
minZ = minY = 3.0 / 16.0;
|
||||
maxZ = maxY = 13.0 / 16.0;
|
||||
maxX = 1.0;
|
||||
minX = 5.0 / 16.0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return VoxelShapes.cuboid(new Box(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
} else {
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTranslucent(BlockState state, BlockView reader, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
package appeng.block.networking;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.client.render.StaticBlockColor;
|
||||
|
||||
public class WirelessRendering extends BlockRenderingCustomizer {
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
rendering.blockColor(new StaticBlockColor(AEColor.TRANSPARENT));
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
package appeng.block.paint;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import appeng.helpers.Splotch;
|
||||
|
||||
/**
|
||||
* Used to transfer the state about paint splotches from the game thread to the
|
||||
* render thread.
|
||||
*/
|
||||
public class PaintSplotches {
|
||||
|
||||
private final List<Splotch> splotches;
|
||||
|
||||
public PaintSplotches(Collection<Splotch> splotches) {
|
||||
this.splotches = ImmutableList.copyOf(splotches);
|
||||
}
|
||||
|
||||
List<Splotch> getSplotches() {
|
||||
return this.splotches;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
|
||||
package appeng.block.paint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Splotch;
|
||||
import appeng.tile.misc.PaintSplotchesBlockEntity;
|
||||
|
||||
/**
|
||||
* Renders paint blocks, which render multiple "splotches" that have been
|
||||
* applied to the sides of adjacent blocks using a matter cannon with paint
|
||||
* balls.
|
||||
*/
|
||||
class PaintSplotchesBakedModel implements IDynamicBakedModel {
|
||||
|
||||
private static final SpriteIdentifier TEXTURE_PAINT1 = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/paint1"));
|
||||
private static final SpriteIdentifier TEXTURE_PAINT2 = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/paint2"));
|
||||
private static final SpriteIdentifier TEXTURE_PAINT3 = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/paint3"));
|
||||
|
||||
private final Sprite[] textures;
|
||||
|
||||
PaintSplotchesBakedModel(Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
this.textures = new Sprite[] { bakedTextureGetter.apply(TEXTURE_PAINT1),
|
||||
bakedTextureGetter.apply(TEXTURE_PAINT2), bakedTextureGetter.apply(TEXTURE_PAINT3) };
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
|
||||
@Nonnull IModelData extraData) {
|
||||
|
||||
if (side != null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
PaintSplotches splotchesState = extraData.getData(PaintSplotchesBlockEntity.SPLOTCHES);
|
||||
|
||||
if (splotchesState == null) {
|
||||
// This is the inventory model which should usually not be used other than in
|
||||
// special cases
|
||||
List<BakedQuad> quads = new ArrayList<>(1);
|
||||
CubeBuilder builder = new CubeBuilder(quads);
|
||||
builder.setTexture(this.textures[0]);
|
||||
builder.addCube(0, 0, 0, 16, 16, 16);
|
||||
return quads;
|
||||
}
|
||||
|
||||
List<Splotch> splotches = splotchesState.getSplotches();
|
||||
|
||||
CubeBuilder builder = new CubeBuilder();
|
||||
|
||||
float offsetConstant = 0.001f;
|
||||
for (final Splotch s : splotches) {
|
||||
|
||||
if (s.isLumen()) {
|
||||
builder.setColorRGB(s.getColor().whiteVariant);
|
||||
builder.setRenderFullBright(true);
|
||||
} else {
|
||||
builder.setColorRGB(s.getColor().mediumVariant);
|
||||
builder.setRenderFullBright(false);
|
||||
}
|
||||
|
||||
float offset = offsetConstant;
|
||||
offsetConstant += 0.001f;
|
||||
|
||||
final float buffer = 0.1f;
|
||||
|
||||
float pos_x = s.x();
|
||||
float pos_y = s.y();
|
||||
|
||||
pos_x = Math.max(buffer, Math.min(1.0f - buffer, pos_x));
|
||||
pos_y = Math.max(buffer, Math.min(1.0f - buffer, pos_y));
|
||||
|
||||
Sprite ico = this.textures[s.getSeed() % this.textures.length];
|
||||
builder.setTexture(ico);
|
||||
builder.setCustomUv(s.getSide().getOpposite(), 0, 0, 16, 16);
|
||||
|
||||
switch (s.getSide()) {
|
||||
case UP:
|
||||
offset = 1.0f - offset;
|
||||
builder.addQuad(Direction.DOWN, pos_x - buffer, offset, pos_y - buffer, pos_x + buffer, offset,
|
||||
pos_y + buffer);
|
||||
break;
|
||||
|
||||
case DOWN:
|
||||
builder.addQuad(Direction.UP, pos_x - buffer, offset, pos_y - buffer, pos_x + buffer, offset,
|
||||
pos_y + buffer);
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
offset = 1.0f - offset;
|
||||
builder.addQuad(Direction.WEST, offset, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer,
|
||||
pos_y + buffer);
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
builder.addQuad(Direction.EAST, offset, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer,
|
||||
pos_y + buffer);
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
offset = 1.0f - offset;
|
||||
builder.addQuad(Direction.NORTH, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer,
|
||||
pos_y + buffer, offset);
|
||||
break;
|
||||
|
||||
case NORTH:
|
||||
builder.addQuad(Direction.SOUTH, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer,
|
||||
pos_y + buffer, offset);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.textures[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return ModelOverrideList.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static List<SpriteIdentifier> getRequiredTextures() {
|
||||
return ImmutableList.of(TEXTURE_PAINT1, TEXTURE_PAINT2, TEXTURE_PAINT3);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.paint;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.misc.PaintSplotchesBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PaintSplotchesBlock extends AEBaseTileBlock<PaintSplotchesBlockEntity> {
|
||||
public PaintSplotchesBlock() {
|
||||
super(defaultProps(Material.WATER, MaterialColor.CLEAR));
|
||||
this.setFullSize(false);
|
||||
this.setOpaque(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemStacks) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final PaintSplotchesBlockEntity tp = this.getBlockEntity(world, pos);
|
||||
|
||||
if (tp != null) {
|
||||
tp.neighborUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillWithRain(final World w, final BlockPos pos) {
|
||||
if (Platform.isServer()) {
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(final BlockState state, final BlockView w, final BlockPos pos) {
|
||||
final PaintSplotchesBlockEntity tp = this.getBlockEntity(w, pos);
|
||||
|
||||
if (tp != null) {
|
||||
return tp.getLightLevel();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir(final BlockState state, final BlockView world, final BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceable(BlockState state, ItemPlacementContext useContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceable(BlockState p_225541_1_, Fluid p_225541_2_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
|
||||
package appeng.block.paint;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
public class PaintSplotchesModel implements IModelGeometry<PaintSplotchesModel> {
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
return new PaintSplotchesBakedModel(spriteGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return PaintSplotchesBakedModel.getRequiredTextures();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
package appeng.block.paint;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
public class PaintSplotchesRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
// Disable auto rotation
|
||||
rendering.modelCustomizer((location, model) -> model);
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.tile.qnb.QuantumBridgeBlockEntity;
|
||||
|
||||
class QnbFormedBakedModel implements IDynamicBakedModel {
|
||||
|
||||
private static final SpriteIdentifier TEXTURE_LINK = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/quantum_link"));
|
||||
private static final SpriteIdentifier TEXTURE_RING = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/quantum_ring"));
|
||||
private static final SpriteIdentifier TEXTURE_RING_LIGHT = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/quantum_ring_light"));
|
||||
private static final SpriteIdentifier TEXTURE_RING_LIGHT_CORNER = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "block/quantum_ring_light_corner"));
|
||||
private static final SpriteIdentifier TEXTURE_CABLE_GLASS = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/glass/transparent"));
|
||||
private static final SpriteIdentifier TEXTURE_COVERED_CABLE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX,
|
||||
new Identifier(AppEng.MOD_ID, "parts/cable/covered/transparent"));
|
||||
|
||||
private static final float DEFAULT_RENDER_MIN = 2.0f;
|
||||
private static final float DEFAULT_RENDER_MAX = 14.0f;
|
||||
|
||||
private static final float CORNER_POWERED_RENDER_MIN = 3.9f;
|
||||
private static final float CORNER_POWERED_RENDER_MAX = 12.1f;
|
||||
|
||||
private static final float CENTER_POWERED_RENDER_MIN = -0.01f;
|
||||
private static final float CENTER_POWERED_RENDER_MAX = 16.01f;
|
||||
|
||||
private final BakedModel baseModel;
|
||||
|
||||
private final Block linkBlock;
|
||||
|
||||
private final Sprite linkTexture;
|
||||
private final Sprite ringTexture;
|
||||
private final Sprite glassCableTexture;
|
||||
private final Sprite coveredCableTexture;
|
||||
private final Sprite lightTexture;
|
||||
private final Sprite lightCornerTexture;
|
||||
|
||||
public QnbFormedBakedModel(BakedModel baseModel, Function<SpriteIdentifier, Sprite> bakedTextureGetter) {
|
||||
this.baseModel = baseModel;
|
||||
this.linkTexture = bakedTextureGetter.apply(TEXTURE_LINK);
|
||||
this.ringTexture = bakedTextureGetter.apply(TEXTURE_RING);
|
||||
this.glassCableTexture = bakedTextureGetter.apply(TEXTURE_CABLE_GLASS);
|
||||
this.coveredCableTexture = bakedTextureGetter.apply(TEXTURE_COVERED_CABLE);
|
||||
this.lightTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT);
|
||||
this.lightCornerTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT_CORNER);
|
||||
this.linkBlock = AEApi.instance().definitions().blocks().quantumLink().maybeBlock().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
|
||||
IModelData modelData) {
|
||||
QnbFormedState formedState = modelData.getData(QuantumBridgeBlockEntity.FORMED_STATE);
|
||||
|
||||
if (formedState == null) {
|
||||
return this.baseModel.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
if (side != null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.getQuads(formedState, state);
|
||||
}
|
||||
|
||||
private List<BakedQuad> getQuads(QnbFormedState formedState, BlockState state) {
|
||||
CubeBuilder builder = new CubeBuilder();
|
||||
|
||||
if (state.getBlock() == this.linkBlock) {
|
||||
Set<Direction> sides = formedState.getAdjacentQuantumBridges();
|
||||
|
||||
this.renderCableAt(builder, 0.11f * 16, this.glassCableTexture, 0.141f * 16, sides);
|
||||
|
||||
this.renderCableAt(builder, 0.188f * 16, this.coveredCableTexture, 0.1875f * 16, sides);
|
||||
|
||||
builder.setTexture(this.linkTexture);
|
||||
builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX,
|
||||
DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX);
|
||||
} else {
|
||||
if (formedState.isCorner()) {
|
||||
this.renderCableAt(builder, 0.188f * 16, this.coveredCableTexture, 0.05f * 16,
|
||||
formedState.getAdjacentQuantumBridges());
|
||||
|
||||
builder.setTexture(this.ringTexture);
|
||||
builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX,
|
||||
DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX);
|
||||
|
||||
if (formedState.isPowered()) {
|
||||
builder.setTexture(this.lightCornerTexture);
|
||||
builder.setRenderFullBright(true);
|
||||
for (Direction facing : Direction.values()) {
|
||||
// Offset the face by a slight amount so that it is drawn over the already drawn
|
||||
// ring texture
|
||||
// (avoids z-fighting)
|
||||
float xOffset = Math.abs(facing.getOffsetX() * 0.01f);
|
||||
float yOffset = Math.abs(facing.getOffsetY() * 0.01f);
|
||||
float zOffset = Math.abs(facing.getOffsetZ() * 0.01f);
|
||||
|
||||
builder.setDrawFaces(EnumSet.of(facing));
|
||||
builder.addCube(DEFAULT_RENDER_MIN - xOffset, DEFAULT_RENDER_MIN - yOffset,
|
||||
DEFAULT_RENDER_MIN - zOffset, DEFAULT_RENDER_MAX + xOffset,
|
||||
DEFAULT_RENDER_MAX + yOffset, DEFAULT_RENDER_MAX + zOffset);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
builder.setTexture(this.ringTexture);
|
||||
|
||||
builder.addCube(0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 16, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX);
|
||||
|
||||
builder.addCube(DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, 16, DEFAULT_RENDER_MAX);
|
||||
|
||||
builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, 16);
|
||||
|
||||
if (formedState.isPowered()) {
|
||||
builder.setTexture(this.lightTexture);
|
||||
builder.setRenderFullBright(true);
|
||||
for (Direction facing : Direction.values()) {
|
||||
// Offset the face by a slight amount so that it is drawn over the already drawn
|
||||
// ring texture
|
||||
// (avoids z-fighting)
|
||||
float xOffset = Math.abs(facing.getOffsetX() * 0.01f);
|
||||
float yOffset = Math.abs(facing.getOffsetY() * 0.01f);
|
||||
float zOffset = Math.abs(facing.getOffsetZ() * 0.01f);
|
||||
|
||||
builder.setDrawFaces(EnumSet.of(facing));
|
||||
builder.addCube(-xOffset, -yOffset, -zOffset, 16 + xOffset, 16 + yOffset, 16 + zOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
private void renderCableAt(CubeBuilder builder, float thickness, Sprite texture, float pull,
|
||||
Set<Direction> connections) {
|
||||
builder.setTexture(texture);
|
||||
|
||||
if (connections.contains(Direction.WEST)) {
|
||||
builder.addCube(0, 8 - thickness, 8 - thickness, 8 - thickness - pull, 8 + thickness, 8 + thickness);
|
||||
}
|
||||
|
||||
if (connections.contains(Direction.EAST)) {
|
||||
builder.addCube(8 + thickness + pull, 8 - thickness, 8 - thickness, 16, 8 + thickness, 8 + thickness);
|
||||
}
|
||||
|
||||
if (connections.contains(Direction.NORTH)) {
|
||||
builder.addCube(8 - thickness, 8 - thickness, 0, 8 + thickness, 8 + thickness, 8 - thickness - pull);
|
||||
}
|
||||
|
||||
if (connections.contains(Direction.SOUTH)) {
|
||||
builder.addCube(8 - thickness, 8 - thickness, 8 + thickness + pull, 8 + thickness, 8 + thickness, 16);
|
||||
}
|
||||
|
||||
if (connections.contains(Direction.DOWN)) {
|
||||
builder.addCube(8 - thickness, 0, 8 - thickness, 8 + thickness, 8 - thickness - pull, 8 + thickness);
|
||||
}
|
||||
|
||||
if (connections.contains(Direction.UP)) {
|
||||
builder.addCube(8 - thickness, 8 + thickness + pull, 8 - thickness, 8 + thickness, 16, 8 + thickness);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelOverrideList getOverrides() {
|
||||
return this.baseModel.getOverrides();
|
||||
}
|
||||
|
||||
public static List<SpriteIdentifier> getRequiredTextures() {
|
||||
return ImmutableList.of(TEXTURE_LINK, TEXTURE_RING, TEXTURE_CABLE_GLASS, TEXTURE_COVERED_CABLE,
|
||||
TEXTURE_RING_LIGHT, TEXTURE_RING_LIGHT_CORNER);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.IModelTransform;
|
||||
import net.minecraft.client.render.model.IUnbakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class QnbFormedModel implements IModelGeometry<QnbFormedModel> {
|
||||
|
||||
private static final Identifier MODEL_RING = new Identifier(AppEng.MOD_ID, "block/qnb/ring");
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
|
||||
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
|
||||
ModelOverrideList overrides, Identifier modelLocation) {
|
||||
BakedModel ringModel = bakery.getBakedModel(MODEL_RING, modelTransform, spriteGetter);
|
||||
return new QnbFormedBakedModel(ringModel, spriteGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
|
||||
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return QnbFormedBakedModel.getRequiredTextures();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
public class QnbFormedState {
|
||||
|
||||
private final Set<Direction> adjacentQuantumBridges;
|
||||
|
||||
private final boolean corner;
|
||||
|
||||
private final boolean powered;
|
||||
|
||||
public QnbFormedState(Set<Direction> adjacentQuantumBridges, boolean corner, boolean powered) {
|
||||
this.adjacentQuantumBridges = adjacentQuantumBridges;
|
||||
this.corner = corner;
|
||||
this.powered = powered;
|
||||
}
|
||||
|
||||
public Set<Direction> getAdjacentQuantumBridges() {
|
||||
return this.adjacentQuantumBridges;
|
||||
}
|
||||
|
||||
public boolean isCorner() {
|
||||
return this.corner;
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return this.powered;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.qnb.QuantumBridgeBlockEntity;
|
||||
|
||||
public abstract class QuantumBaseBlock extends AEBaseTileBlock<QuantumBridgeBlockEntity> {
|
||||
|
||||
public static final BooleanProperty FORMED = BooleanProperty.of("formed");
|
||||
|
||||
private static final VoxelShape SHAPE;
|
||||
|
||||
static {
|
||||
final float shave = 2.0f / 16.0f;
|
||||
SHAPE = VoxelShapes.cuboid(new Box(shave, shave, shave, 1.0f - shave, 1.0f - shave, 1.0f - shave));
|
||||
}
|
||||
|
||||
public QuantumBaseBlock(Settings props) {
|
||||
super(props);
|
||||
this.setFullSize(this.setOpaque(false));
|
||||
this.setDefaultState(this.getDefaultState().with(FORMED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(FORMED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, QuantumBridgeBlockEntity te) {
|
||||
return currentState.with(FORMED, te.isFormed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final QuantumBridgeBlockEntity bridge = this.getBlockEntity(world, pos);
|
||||
if (bridge != null) {
|
||||
bridge.neighborUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateReplaced(BlockState state, World w, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (newState.getBlock() == state.getBlock()) {
|
||||
return; // Just a block state change
|
||||
}
|
||||
|
||||
final QuantumBridgeBlockEntity bridge = this.getBlockEntity(w, pos);
|
||||
if (bridge != null) {
|
||||
bridge.breakCluster();
|
||||
}
|
||||
|
||||
super.onStateReplaced(state, w, pos, newState, isMoving);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
public class QuantumBridgeRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
// Disable auto rotation
|
||||
rendering.modelCustomizer((location, model) -> model);
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.client.EffectType;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.QNBContainer;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.AEGlassMaterial;
|
||||
import appeng.tile.qnb.QuantumBridgeBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class QuantumLinkChamberBlock extends QuantumBaseBlock {
|
||||
|
||||
private static final VoxelShape SHAPE;
|
||||
|
||||
static {
|
||||
final double onePixel = 2.0 / 16.0;
|
||||
SHAPE = VoxelShapes.cuboid(
|
||||
new Box(onePixel, onePixel, onePixel, 1.0 - onePixel, 1.0 - onePixel, 1.0 - onePixel));
|
||||
}
|
||||
|
||||
public QuantumLinkChamberBlock() {
|
||||
super(defaultProps(AEGlassMaterial.INSTANCE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random rand) {
|
||||
final QuantumBridgeBlockEntity bridge = this.getBlockEntity(w, pos);
|
||||
if (bridge != null) {
|
||||
if (bridge.hasQES()) {
|
||||
if (AppEng.instance().shouldAddParticles(rand)) {
|
||||
AppEng.instance().spawnEffect(EffectType.Energy, w, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final QuantumBridgeBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(QNBContainer.TYPE, p, ContainerLocator.forTileEntity(tg));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.qnb;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
import appeng.tile.qnb.QuantumBridgeBlockEntity;
|
||||
|
||||
public class QuantumRingBlock extends QuantumBaseBlock {
|
||||
|
||||
private static final VoxelShape SHAPE = createShape(2.0 / 16.0);
|
||||
private static final VoxelShape SHAPE_CORNER = createShape(4.0 / 16.0);
|
||||
private static final VoxelShape SHAPE_FORMED = createShape(1.0 / 16.0);
|
||||
|
||||
public QuantumRingBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
|
||||
final QuantumBridgeBlockEntity bridge = this.getBlockEntity(w, pos);
|
||||
if (bridge != null && bridge.isCorner()) {
|
||||
return SHAPE_CORNER;
|
||||
} else if (bridge != null && bridge.isFormed()) {
|
||||
return SHAPE_FORMED;
|
||||
}
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
private static VoxelShape createShape(double onePixel) {
|
||||
return VoxelShapes.cuboid(
|
||||
new Box(onePixel, onePixel, onePixel, 1.0 - onePixel, 1.0 - onePixel, 1.0 - onePixel));
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.spatial;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.World;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.block.AEBaseBlock;
|
||||
|
||||
/**
|
||||
* This block is used to fill empty space in spatial dimensions and delinates
|
||||
* the border of a spatial dimensions's usable space.
|
||||
*/
|
||||
public class MatrixFrameBlock extends AEBaseBlock {
|
||||
|
||||
private static final Material MATERIAL = new Material(MaterialColor.CLEAR, false, true, true, false, false, false,
|
||||
false, PistonBehavior.PUSH_ONLY);
|
||||
|
||||
public MatrixFrameBlock() {
|
||||
super(Settings.create(MATERIAL).strength(-1.0F, 6000000.0F).notSolid().noDrops());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.INVISIBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemStacks) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
|
||||
ShapeContext context) {
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
// This also prevents any blocks from being placed on this block!
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView worldIn, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExplosionDestroy(final World world, final BlockPos pos, final Explosion explosion) {
|
||||
// Don't explode.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTranslucent(BlockState state, BlockView reader, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAmbientOcclusionLightValue(BlockState state, BlockView worldIn, BlockPos pos) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEntityDestroy(final BlockState state, final BlockView world, final BlockPos pos,
|
||||
final Entity entity) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.spatial;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.SpatialIOPortContainer;
|
||||
import appeng.tile.spatial.SpatialIOPortBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class SpatialIOPortBlock extends AEBaseTileBlock<SpatialIOPortBlockEntity> {
|
||||
|
||||
public SpatialIOPortBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final SpatialIOPortBlockEntity te = this.getBlockEntity(world, pos);
|
||||
if (te != null) {
|
||||
te.updateRedstoneState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final SpatialIOPortBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(SpatialIOPortContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ChestContainer;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.tile.storage.ChestBlockEntity;
|
||||
|
||||
public class ChestBlock extends AEBaseTileBlock<ChestBlockEntity> {
|
||||
|
||||
private final static EnumProperty<DriveSlotState> SLOT_STATE = EnumProperty.create("slot_state",
|
||||
DriveSlotState.class);
|
||||
|
||||
public ChestBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
this.setDefaultState(this.getDefaultState().with(SLOT_STATE, DriveSlotState.EMPTY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(SLOT_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, ChestBlockEntity te) {
|
||||
DriveSlotState slotState = DriveSlotState.EMPTY;
|
||||
|
||||
if (te.getCellCount() >= 1) {
|
||||
slotState = DriveSlotState.fromCellStatus(te.getCellStatus(0));
|
||||
}
|
||||
// Power-state has to be checked separately
|
||||
if (!te.isPowered() && slotState != DriveSlotState.EMPTY) {
|
||||
slotState = DriveSlotState.OFFLINE;
|
||||
}
|
||||
|
||||
return currentState.with(SLOT_STATE, slotState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
final ChestBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null && !p.isInSneakingPose()) {
|
||||
if (w.isClient()) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (hit.getSide() == tg.getUp()) {
|
||||
if (!tg.openGui(p)) {
|
||||
p.sendSystemMessage(PlayerMessages.ChestCannotReadStorageCell.get(), Util.NIL_UUID);
|
||||
}
|
||||
} else {
|
||||
ContainerOpener.openContainer(ChestContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.DriveContainer;
|
||||
import appeng.tile.storage.DriveBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class DriveBlock extends AEBaseTileBlock<DriveBlockEntity> {
|
||||
|
||||
public DriveBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final DriveBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(DriveContainer.TYPE, p, ContainerLocator.forTileEntity(tg));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
|
||||
public class DriveRendering extends BlockRenderingCustomizer {
|
||||
@Override
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
|
||||
import appeng.api.storage.cells.CellState;
|
||||
|
||||
/**
|
||||
* Describes the different states a single slot of a BlockDrive can be in in
|
||||
* terms of rendering.
|
||||
*/
|
||||
public enum DriveSlotState implements StringIdentifiable {
|
||||
|
||||
// No cell in slot
|
||||
EMPTY("empty"),
|
||||
|
||||
// Cell in slot, but unpowered
|
||||
OFFLINE("offline"),
|
||||
|
||||
// Online and free space
|
||||
ONLINE("online"),
|
||||
|
||||
// Types full, space left
|
||||
TYPES_FULL("types_full"),
|
||||
|
||||
// Completely full
|
||||
FULL("full");
|
||||
|
||||
private final String name;
|
||||
|
||||
DriveSlotState(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static DriveSlotState fromCellStatus(CellState cellStatus) {
|
||||
switch (cellStatus) {
|
||||
default:
|
||||
case ABSENT:
|
||||
return DriveSlotState.EMPTY;
|
||||
case EMPTY:
|
||||
case NOT_EMPTY:
|
||||
return DriveSlotState.ONLINE;
|
||||
case TYPES_FULL:
|
||||
return DriveSlotState.TYPES_FULL;
|
||||
case FULL:
|
||||
return DriveSlotState.FULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.storage.cells.CellState;
|
||||
|
||||
/**
|
||||
* Contains the full information about what the state of the slots in a
|
||||
* BlockDrive is.
|
||||
*/
|
||||
public class DriveSlotsState {
|
||||
|
||||
private final Item[] cells;
|
||||
|
||||
private final DriveSlotState[] states;
|
||||
|
||||
public DriveSlotsState(Item[] cells, DriveSlotState[] states) {
|
||||
Preconditions.checkArgument(cells.length == states.length);
|
||||
this.cells = cells;
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public DriveSlotState getState(int index) {
|
||||
if (index >= this.states.length) {
|
||||
return DriveSlotState.EMPTY;
|
||||
}
|
||||
return this.states[index];
|
||||
}
|
||||
|
||||
public Item getCell(int index) {
|
||||
if (index >= this.cells.length) {
|
||||
return null;
|
||||
}
|
||||
return this.cells[index];
|
||||
}
|
||||
|
||||
public int getSlotCount() {
|
||||
return this.cells.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an array that describes the state of each slot in this drive or
|
||||
* chest.
|
||||
*/
|
||||
public static DriveSlotsState fromChestOrDrive(IChestOrDrive chestOrDrive) {
|
||||
DriveSlotState[] states = new DriveSlotState[chestOrDrive.getCellCount()];
|
||||
Item[] cells = new Item[chestOrDrive.getCellCount()];
|
||||
for (int i = 0; i < chestOrDrive.getCellCount(); i++) {
|
||||
cells[i] = chestOrDrive.getCellItem(i);
|
||||
|
||||
if (!chestOrDrive.isPowered()) {
|
||||
if (chestOrDrive.getCellStatus(i) != CellState.EMPTY) {
|
||||
states[i] = DriveSlotState.OFFLINE;
|
||||
} else {
|
||||
states[i] = DriveSlotState.EMPTY;
|
||||
}
|
||||
} else {
|
||||
states[i] = DriveSlotState.fromCellStatus(chestOrDrive.getCellStatus(i));
|
||||
}
|
||||
}
|
||||
return new DriveSlotsState(cells, states);
|
||||
}
|
||||
|
||||
public static DriveSlotsState createEmpty(int slotCount) {
|
||||
DriveSlotState[] states = new DriveSlotState[slotCount];
|
||||
Item[] cells = new Item[slotCount];
|
||||
for (int i = 0; i < slotCount; i++) {
|
||||
states[i] = DriveSlotState.EMPTY;
|
||||
}
|
||||
return new DriveSlotsState(cells, states);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.IOPortContainer;
|
||||
import appeng.tile.storage.IOPortBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class IOPortBlock extends AEBaseTileBlock<IOPortBlockEntity> {
|
||||
|
||||
public IOPortBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final IOPortBlockEntity te = this.getBlockEntity(world, pos);
|
||||
if (te != null) {
|
||||
te.updateRedstoneState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (p.isInSneakingPose()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
final IOPortBlockEntity tg = this.getBlockEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(IOPortContainer.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.storage.SkyChestBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class SkyChestBlock extends AEBaseTileBlock<SkyChestBlockEntity> {
|
||||
|
||||
private static final double AABB_OFFSET_BOTTOM = 0.00;
|
||||
private static final double AABB_OFFSET_SIDES = 0.06;
|
||||
private static final double AABB_OFFSET_TOP = 0.125;
|
||||
|
||||
public enum SkyChestType {
|
||||
STONE, BLOCK
|
||||
};
|
||||
|
||||
public final SkyChestType type;
|
||||
|
||||
public SkyChestBlock(final SkyChestType type, Settings props) {
|
||||
super(props);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTranslucent(BlockState state, BlockView reader, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (Platform.isServer()) {
|
||||
SkyChestBlockEntity tile = getBlockEntity(w, pos);
|
||||
if (tile == null) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
throw new IllegalStateException();
|
||||
// FIXME FABRIC ContainerOpener.openContainer(SkyChestContainer.TYPE, player, ContainerLocator.forTileEntity(tile));
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
|
||||
// TODO Cache this! It can't be that hard!
|
||||
Box aabb = computeAABB(worldIn, pos);
|
||||
return VoxelShapes.cuboid(aabb);
|
||||
}
|
||||
|
||||
private Box computeAABB(final BlockView w, final BlockPos pos) {
|
||||
final SkyChestBlockEntity sk = this.getBlockEntity(w, pos);
|
||||
Direction o = Direction.UP;
|
||||
|
||||
if (sk != null) {
|
||||
o = sk.getUp();
|
||||
}
|
||||
|
||||
final double offsetX = o.getOffsetX() == 0 ? AABB_OFFSET_SIDES : 0.0;
|
||||
final double offsetY = o.getOffsetY() == 0 ? AABB_OFFSET_SIDES : 0.0;
|
||||
final double offsetZ = o.getOffsetZ() == 0 ? AABB_OFFSET_SIDES : 0.0;
|
||||
|
||||
// for x/z top and bottom is swapped
|
||||
final double minX = Math.max(0.0,
|
||||
offsetX + (o.getOffsetX() < 0 ? AABB_OFFSET_BOTTOM : (o.getOffsetX() * AABB_OFFSET_TOP)));
|
||||
final double minY = Math.max(0.0,
|
||||
offsetY + (o.getOffsetY() < 0 ? AABB_OFFSET_TOP : (o.getOffsetY() * AABB_OFFSET_BOTTOM)));
|
||||
final double minZ = Math.max(0.0,
|
||||
offsetZ + (o.getOffsetZ() < 0 ? AABB_OFFSET_BOTTOM : (o.getOffsetZ() * AABB_OFFSET_TOP)));
|
||||
|
||||
final double maxX = Math.min(1.0,
|
||||
1.0 - offsetX - (o.getOffsetX() < 0 ? AABB_OFFSET_TOP : (o.getOffsetX() * AABB_OFFSET_BOTTOM)));
|
||||
final double maxY = Math.min(1.0,
|
||||
1.0 - offsetY - (o.getOffsetY() < 0 ? AABB_OFFSET_BOTTOM : (o.getOffsetY() * AABB_OFFSET_TOP)));
|
||||
final double maxZ = Math.min(1.0,
|
||||
1.0 - offsetZ - (o.getOffsetZ() < 0 ? AABB_OFFSET_TOP : (o.getOffsetZ() * AABB_OFFSET_BOTTOM)));
|
||||
|
||||
return new Box(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.AEBaseBlockItem;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.BlockDefinition;
|
||||
import appeng.core.features.TileDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class BlockDefinitionBuilder implements IBlockBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
|
||||
private boolean disableItem = false;
|
||||
|
||||
private BiFunction<Block, Item.Settings, BlockItem> itemFactory;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BlockRendering blockRendering;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
BlockDefinitionBuilder(FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier) {
|
||||
this.factory = factory;
|
||||
this.id = new Identifier(AppEng.MOD_ID, id);
|
||||
this.blockSupplier = blockSupplier;
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering = new BlockRendering(this.id);
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> callback) {
|
||||
this.bootstrapComponents.add(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering(BlockRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition) {
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder item(BiFunction<Block, Item.Settings, BlockItem> factory) {
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder disableItem() {
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void customizeForClient(BlockRenderingCustomizer callback) {
|
||||
callback.customize(this.blockRendering, this.itemRendering);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build() {
|
||||
// Create block and matching item, and set factory name of both
|
||||
Block block = this.blockSupplier.get();
|
||||
|
||||
// Register the item and block with the game
|
||||
Registry.register(Registry.BLOCK, id, block);
|
||||
BlockItem item = this.constructItemFromBlock(block);
|
||||
if (item != null) {
|
||||
Registry.register(Registry.ITEM, id, item);
|
||||
}
|
||||
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(block, item)));
|
||||
|
||||
if (this.tileEntityDefinition != null) {
|
||||
// Tell the block entity definition about the block we've registered
|
||||
this.tileEntityDefinition.addBlock(block);
|
||||
}
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering.apply(this.factory, block);
|
||||
|
||||
if (item != null) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
}
|
||||
|
||||
T definition;
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
definition = (T) new TileDefinition(this.id.getPath(), (AEBaseTileBlock<?>) block, item, features);
|
||||
} else {
|
||||
definition = (T) new BlockDefinition(this.id.getPath(), block, item, features);
|
||||
}
|
||||
|
||||
if (itemGroup == CreativeTab.INSTANCE) {
|
||||
CreativeTab.add(definition);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BlockItem constructItemFromBlock(Block block) {
|
||||
if (this.disableItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Item.Settings itemProperties = new Item.Settings();
|
||||
|
||||
if (itemGroup != null) {
|
||||
itemProperties.group(itemGroup);
|
||||
}
|
||||
// FIXME: Allow more/all item properties
|
||||
|
||||
if (this.itemFactory != null) {
|
||||
return this.itemFactory.apply(block, itemProperties);
|
||||
} else if (block instanceof AEBaseBlock) {
|
||||
return new AEBaseBlockItem(block, itemProperties);
|
||||
} else {
|
||||
return new BlockItem(block, itemProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.IClientSetupComponent;
|
||||
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.BlockStackSrc;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
/**
|
||||
* Used to define our block entities and all of their properties that are
|
||||
* relevant to registering them.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class BlockEntityBuilder<T extends AEBaseBlockEntity> {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
// The block entity class
|
||||
private final Class<T> tileClass;
|
||||
|
||||
private BlockEntityType<T> type;
|
||||
|
||||
// The factory for creating block entity objects
|
||||
private final Function<BlockEntityType<T>, T> supplier;
|
||||
|
||||
private TileEntityRendering<T> tileEntityRendering;
|
||||
|
||||
private final List<Block> blocks = new ArrayList<>();
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public BlockEntityBuilder(FeatureFactory factory, String id, Class<T> tileClass,
|
||||
Function<BlockEntityType<T>, T> supplier) {
|
||||
this.factory = factory;
|
||||
this.id = AppEng.makeId(id);
|
||||
this.tileClass = tileClass;
|
||||
this.supplier = supplier;
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.tileEntityRendering = new TileEntityRendering<>();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> rendering(TileEntityRenderingCustomizer<T> customizer) {
|
||||
customizer.customize(tileEntityRendering);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public TileEntityDefinition build() {
|
||||
|
||||
this.factory.addBootstrapComponent((ITileEntityRegistrationComponent) () -> {
|
||||
if (blocks.isEmpty()) {
|
||||
throw new IllegalStateException("No blocks make use of this block entity: " + tileClass);
|
||||
}
|
||||
|
||||
Supplier<T> factory = () -> supplier.apply(type);
|
||||
type = BlockEntityType.Builder.create(factory, blocks.toArray(new Block[0])).build(null);
|
||||
|
||||
Registry.register(Registry.BLOCK_ENTITY_TYPE, id, type);
|
||||
|
||||
AEBaseBlockEntity.registerTileItem(tileClass, new BlockStackSrc(blocks.get(0), ActivityState.Enabled));
|
||||
|
||||
for (Block block : blocks) {
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
AEBaseTileBlock<T> baseTileBlock = (AEBaseTileBlock<T>) block;
|
||||
baseTileBlock.setTileEntity(tileClass, factory);
|
||||
}
|
||||
}
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
buildClient();
|
||||
}
|
||||
});
|
||||
|
||||
return new TileEntityDefinition(this::addBlock);
|
||||
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void buildClient() {
|
||||
if (tileEntityRendering.tileEntityRenderer != null) {
|
||||
BlockEntityRendererRegistry.INSTANCE.register(type, tileEntityRendering.tileEntityRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
private void addBlock(Block block) {
|
||||
Preconditions.checkState(type == null, "No more blocks can be added after registration completed.");
|
||||
this.blocks.add(block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.RenderTypeComponent;
|
||||
|
||||
class BlockRendering implements IBlockRendering {
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BiFunction<Identifier, BakedModel, BakedModel> modelCustomizer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BlockColorProvider blockColor;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private RenderLayer renderType;
|
||||
|
||||
public BlockRendering(Identifier id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public IBlockRendering modelCustomizer(BiFunction<Identifier, BakedModel, BakedModel> customizer) {
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering blockColor(BlockColorProvider blockColor) {
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockRendering renderType(RenderLayer type) {
|
||||
this.renderType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply(FeatureFactory factory, Block block) {
|
||||
if (this.modelCustomizer != null) {
|
||||
factory.addModelOverride(id.getPath(), this.modelCustomizer);
|
||||
} else if (block instanceof AEBaseTileBlock) {
|
||||
// This is a default rotating model if the base-block uses an AE block entity
|
||||
// which exposes UP/FRONT as
|
||||
// extended props
|
||||
// FIXME FABRIC factory.addModelOverride(id.getPath(), (l, m) -> new AutoRotatingBakedModel(m));
|
||||
}
|
||||
|
||||
if (this.blockColor != null) {
|
||||
factory.addBootstrapComponent(new BlockColorComponent(block, this.blockColor));
|
||||
}
|
||||
|
||||
if (this.renderType != null) {
|
||||
factory.addBootstrapComponent(new RenderTypeComponent(block, this.renderType));
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-11
@@ -16,22 +16,19 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.spatial;
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
/**
|
||||
* A callback that allows the rendering of a block to be customized. Sadly this
|
||||
* class is required and no lambdas can be used due to them not being able to be
|
||||
* annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public abstract class BlockRenderingCustomizer {
|
||||
|
||||
public class SpatialPylonRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
}
|
||||
public abstract void customize(IBlockRendering rendering, IItemRendering itemRendering);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricEntityType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Helper to register a custom Entity with Minecraft.
|
||||
*/
|
||||
public class EntityBuilder<T extends Entity> {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final String id;
|
||||
|
||||
private final FabricEntityTypeBuilder<T> builder;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public EntityBuilder(FeatureFactory factory, String id, EntityType.EntityFactory<T> entityFactory,
|
||||
SpawnGroup classification) {
|
||||
this.factory = factory;
|
||||
this.id = id;
|
||||
this.builder = FabricEntityTypeBuilder.create(classification, entityFactory);
|
||||
}
|
||||
|
||||
public EntityBuilder<T> features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityBuilder<T> addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityBuilder<T> customize(Consumer<FabricEntityTypeBuilder<T>> function) {
|
||||
function.accept(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityType<T> build() {
|
||||
EntityType<T> entityType = builder.build();
|
||||
String fullId = "appliedenergistics2:" + this.id;
|
||||
Registry.register(Registry.ENTITY_TYPE, fullId, entityType);
|
||||
return entityType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.ModelOverrideComponent;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class FeatureFactory {
|
||||
|
||||
private final AEFeature[] defaultFeatures;
|
||||
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
|
||||
public FeatureFactory() {
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.modelOverrideComponent = new ModelOverrideComponent();
|
||||
this.addBootstrapComponent(this.modelOverrideComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private FeatureFactory(FeatureFactory parent, AEFeature... defaultFeatures) {
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlockBuilder block(String id, Supplier<Block> block) {
|
||||
return new BlockDefinitionBuilder(this, id, block).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public IItemBuilder item(String id, Function<Item.Settings, Item> itemFactory) {
|
||||
return new ItemDefinitionBuilder(this, id, itemFactory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends Entity> EntityBuilder<T> entity(String id, EntityType.EntityFactory<T> factory,
|
||||
SpawnGroup classification) {
|
||||
return new EntityBuilder<T>(this, id, factory, classification).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends AEBaseBlockEntity> BlockEntityBuilder<T> tileEntity(String id, Class<T> teClass,
|
||||
Function<BlockEntityType<T>, T> factory) {
|
||||
return new BlockEntityBuilder<>(this, id, teClass, factory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public FeatureFactory features(AEFeature... features) {
|
||||
return new FeatureFactory(this, features);
|
||||
}
|
||||
|
||||
public void addBootstrapComponent(IBootstrapComponent component) {
|
||||
Arrays.stream(component.getClass().getInterfaces()).filter(i -> IBootstrapComponent.class.isAssignableFrom(i))
|
||||
.forEach(i -> this.addBootstrapComponent((Class<? extends IBootstrapComponent>) i, component));
|
||||
}
|
||||
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent(Class<? extends IBootstrapComponent> eventType,
|
||||
T component) {
|
||||
this.bootstrapComponents.computeIfAbsent(eventType, c -> new ArrayList<IBootstrapComponent>()).add(component);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
void addModelOverride(String resourcePath, BiFunction<Identifier, BakedModel, BakedModel> customizer) {
|
||||
this.modelOverrideComponent.addOverride(resourcePath, customizer);
|
||||
}
|
||||
|
||||
public <T extends IBootstrapComponent> Iterator<T> getBootstrapComponents(Class<T> eventType) {
|
||||
return (Iterator<T>) this.bootstrapComponents.getOrDefault(eventType, Collections.emptyList()).iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
|
||||
public interface IBlockBuilder {
|
||||
IBlockBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> component);
|
||||
|
||||
IBlockBuilder features(AEFeature... features);
|
||||
|
||||
IBlockBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IBlockBuilder rendering(BlockRenderingCustomizer callback);
|
||||
|
||||
IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition);
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
|
||||
IBlockBuilder item(BiFunction<Block, Item.Settings, BlockItem> factory);
|
||||
|
||||
<T extends IBlockDefinition> T build();
|
||||
}
|
||||
+18
-16
@@ -16,29 +16,31 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.client.render.ColorableTileBlockColor;
|
||||
import appeng.client.render.StaticItemColor;
|
||||
/**
|
||||
* Allows for client-side rendering to be customized in the context of
|
||||
* block/item registration.
|
||||
*/
|
||||
public interface IBlockRendering {
|
||||
|
||||
public class ChestRendering extends BlockRenderingCustomizer {
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
IBlockRendering modelCustomizer(BiFunction<Identifier, BakedModel, BakedModel> customizer);
|
||||
|
||||
// I checked, the ME chest doesn't keep its color in item form
|
||||
itemRendering.color(new StaticItemColor(AEColor.TRANSPARENT));
|
||||
rendering.blockColor(new ColorableTileBlockColor());
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
IBlockRendering blockColor(BlockColorProvider blockColor);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
IBlockRendering renderType(RenderLayer type);
|
||||
|
||||
}
|
||||
+7
-3
@@ -16,8 +16,12 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.spatial;
|
||||
package appeng.bootstrap;
|
||||
|
||||
enum SpatialPylonTextureType {
|
||||
BASE, BASE_END, BASE_SPANNED, DIM, DIM_END, DIM_SPANNED, RED, RED_END, RED_SPANNED
|
||||
/**
|
||||
* Bootstrap components can be registered to take part in the various
|
||||
* initialization phases of Forge. See the individual subclasses for a specific
|
||||
* forge initalization event.
|
||||
*/
|
||||
public interface IBootstrapComponent {
|
||||
}
|
||||
+7
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -16,16 +16,12 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.widgets;
|
||||
package appeng.bootstrap;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import net.minecraft.advancement.criterion.Criterion;
|
||||
import net.minecraft.advancement.criterion.CriterionConditions;
|
||||
|
||||
public interface ISortSource {
|
||||
SortOrder getSortBy();
|
||||
|
||||
SortDir getSortDir();
|
||||
|
||||
ViewItems getSortDisplay();
|
||||
@FunctionalInterface
|
||||
public interface ICriterionTriggerRegistry {
|
||||
void register(Criterion<? extends CriterionConditions> trigger);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
|
||||
/**
|
||||
* Allows an item to be defined and registered with the game. The item is only
|
||||
* registered once build is called.
|
||||
*/
|
||||
public interface IItemBuilder {
|
||||
IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component);
|
||||
|
||||
IItemBuilder features(AEFeature... features);
|
||||
|
||||
IItemBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IItemBuilder itemGroup(ItemGroup tab);
|
||||
|
||||
IItemBuilder props(Consumer<Item.Settings> customizer);
|
||||
|
||||
IItemBuilder rendering(ItemRenderingCustomizer callback);
|
||||
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior(Supplier<DispenserBehavior> behavior);
|
||||
|
||||
ItemDefinition build();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* Allows the rendering of an item to be customized.
|
||||
*/
|
||||
public interface IItemRendering {
|
||||
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint
|
||||
* and returns a color multiplier.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
IItemRendering color(ItemColorProvider itemColor);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.IInitComponent;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
class ItemDefinitionBuilder implements IItemBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
private final Function<Item.Settings, Item> itemFactory;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
|
||||
private final Item.Settings props = new Item.Settings();
|
||||
|
||||
private Supplier<DispenserBehavior> dispenserBehaviorSupplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
ItemDefinitionBuilder(FeatureFactory factory, String id, Function<Item.Settings, Item> itemFactory) {
|
||||
this.factory = factory;
|
||||
this.id = AppEng.makeId(id);
|
||||
this.itemFactory = itemFactory;
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component) {
|
||||
this.boostrapComponents.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder itemGroup(ItemGroup itemGroup) {
|
||||
this.itemGroup = itemGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder props(Consumer<Item.Settings> consumer) {
|
||||
consumer.accept(props);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder rendering(ItemRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior(Supplier<DispenserBehavior> behavior) {
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void customizeForClient(ItemRenderingCustomizer callback) {
|
||||
callback.customize(this.itemRendering);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDefinition build() {
|
||||
props.group(itemGroup);
|
||||
|
||||
Item item = this.itemFactory.apply(props);
|
||||
|
||||
ItemDefinition definition = new ItemDefinition(id.getPath(), item, features);
|
||||
|
||||
// Register all extra handlers
|
||||
this.boostrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(item)));
|
||||
|
||||
// Register custom dispenser behavior if requested
|
||||
if (this.dispenserBehaviorSupplier != null) {
|
||||
this.factory.addBootstrapComponent((IInitComponent) () -> {
|
||||
DispenserBehavior behavior = this.dispenserBehaviorSupplier.get();
|
||||
DispenserBlock.registerBehavior(item, behavior);
|
||||
});
|
||||
}
|
||||
|
||||
Registry.register(Registry.ITEM, id, item);
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
|
||||
if (itemGroup == CreativeTab.INSTANCE) {
|
||||
CreativeTab.add(definition);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.bootstrap.components.ItemColorComponent;
|
||||
|
||||
class ItemRendering implements IItemRendering {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemColorProvider itemColor;
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public IItemRendering color(ItemColorProvider itemColor) {
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply(FeatureFactory factory, Item item) {
|
||||
if (this.itemColor != null) {
|
||||
factory.addBootstrapComponent(new ItemColorComponent(item, this.itemColor));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+9
-21
@@ -16,30 +16,18 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.storage;
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
/**
|
||||
* Describes the type of cell present in a slot.
|
||||
* A callback that allows the rendering of a item to be customized. Sadly this
|
||||
* class is required and no lambdas can be used due to them not being able to be
|
||||
* annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public enum DriveSlotCellType implements StringIdentifiable {
|
||||
|
||||
EMPTY("empty"),
|
||||
|
||||
ITEM("item"),
|
||||
|
||||
FLUID("fluid");
|
||||
|
||||
private final String name;
|
||||
|
||||
DriveSlotCellType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return this.name;
|
||||
}
|
||||
public abstract class ItemRenderingCustomizer {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract void customize(IItemRendering rendering);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ModelsReloadCallback {
|
||||
|
||||
Event<ModelsReloadCallback> EVENT = EventFactory.createArrayBacked(ModelsReloadCallback.class,
|
||||
(listeners) -> (loadedModels) -> {
|
||||
for (ModelsReloadCallback listener : listeners) {
|
||||
listener.onModelsReloaded(loadedModels);
|
||||
}
|
||||
});
|
||||
|
||||
void onModelsReloaded(Map<Identifier, BakedModel> loadedModels);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class TileEntityRendering<T extends AEBaseBlockEntity> {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> tileEntityRenderer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public TileEntityRendering<T> tileEntityRenderer(
|
||||
Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> tileEntityRenderer) {
|
||||
this.tileEntityRenderer = tileEntityRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-27
@@ -16,36 +16,22 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.server;
|
||||
package appeng.bootstrap;
|
||||
|
||||
public enum AccessType {
|
||||
/**
|
||||
* allows basic access to manipulate the block via gui, or other.
|
||||
*/
|
||||
BLOCK_ACCESS,
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
/**
|
||||
* A callback that allows the rendering of a block entity to be customized. Sadly
|
||||
* this class is required and no lambdas can be used due to them not being able
|
||||
* to be annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public interface TileEntityRenderingCustomizer<T extends AEBaseBlockEntity> {
|
||||
|
||||
/**
|
||||
* Can player deposit items into the network.
|
||||
* Declared as a default method because we will carve out the implementations that
|
||||
* override this method on the Server side.
|
||||
*/
|
||||
NETWORK_DEPOSIT,
|
||||
default void customize(TileEntityRendering<T> rendering) {
|
||||
}
|
||||
|
||||
/**
|
||||
* can player withdraw items from the network.
|
||||
*/
|
||||
NETWORK_WITHDRAW,
|
||||
|
||||
/**
|
||||
* can player issue crafting requests?
|
||||
*/
|
||||
NETWORK_CRAFT,
|
||||
|
||||
/**
|
||||
* can player add new blocks to the network.
|
||||
*/
|
||||
NETWORK_BUILD,
|
||||
|
||||
/**
|
||||
* can player manipulate security settings.
|
||||
*/
|
||||
NETWORK_SECURITY
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
|
||||
public class BlockColorComponent implements IInitComponent {
|
||||
|
||||
private final Block block;
|
||||
|
||||
private final BlockColorProvider blockColor;
|
||||
|
||||
public BlockColorComponent(Block block, BlockColorProvider blockColor) {
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
MinecraftClient.getInstance().getBlockColors().registerColorProvider(this.blockColor, this.block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
/**
|
||||
* Will be run during
|
||||
* {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}.
|
||||
*/
|
||||
public interface IClientSetupComponent extends IBootstrapComponent {
|
||||
|
||||
void setup();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IInitComponent extends IBootstrapComponent {
|
||||
void initialize();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
public interface IItemColorRegistrationComponent extends IBootstrapComponent {
|
||||
|
||||
void register();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IModelBakeComponent extends IBootstrapComponent {
|
||||
|
||||
void onModelsReloaded(Map<Identifier, BakedModel> loadedModels);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IPostInitComponent extends IBootstrapComponent {
|
||||
void postInitialize();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ITileEntityRegistrationComponent extends IBootstrapComponent {
|
||||
void register();
|
||||
}
|
||||
+17
-10
@@ -16,19 +16,26 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.block.networking;
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
public class ItemColorComponent implements IItemColorRegistrationComponent {
|
||||
private final Item item;
|
||||
|
||||
private final ItemColorProvider itemColor;
|
||||
|
||||
public ItemColorComponent(Item item, ItemColorProvider itemColor) {
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
|
||||
public class ControllerRendering extends BlockRenderingCustomizer {
|
||||
@Override
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
// Disables the default model rotator
|
||||
rendering.modelCustomizer((loc, model) -> model);
|
||||
rendering.renderType(RenderLayer.getCutout());
|
||||
public void register() {
|
||||
ColorProviderRegistry.ITEM.register(itemColor, item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class ModelOverrideComponent implements IModelBakeComponent {
|
||||
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<Identifier, BakedModel, BakedModel>> customizer = new HashMap<>();
|
||||
|
||||
public void addOverride(String resourcePath, BiFunction<Identifier, BakedModel, BakedModel> customizer) {
|
||||
this.customizer.put(resourcePath, customizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelsReloaded(final Map<Identifier, BakedModel> loadedModels) {
|
||||
Set<Identifier> keys = Sets.newHashSet(loadedModels.keySet());
|
||||
BakedModel missingModel = loadedModels.get(ModelLoader.MISSING);
|
||||
|
||||
for (Identifier location : keys) {
|
||||
if (!location.getNamespace().equals(AppEng.MOD_ID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BakedModel orgModel = loadedModels.get(location);
|
||||
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if (orgModel == missingModel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BiFunction<Identifier, BakedModel, BakedModel> customizer = this.customizer.get(location.getPath());
|
||||
if (customizer != null) {
|
||||
BakedModel newModel = customizer.apply(location, orgModel);
|
||||
|
||||
if (newModel != orgModel) {
|
||||
loadedModels.put(location, newModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
/**
|
||||
* Sets the rendering type for a block.
|
||||
*/
|
||||
public class RenderTypeComponent implements IClientSetupComponent {
|
||||
|
||||
private final Block block;
|
||||
|
||||
private final RenderLayer renderType;
|
||||
|
||||
public RenderTypeComponent(Block block, RenderLayer renderType) {
|
||||
this.block = block;
|
||||
this.renderType = Preconditions.checkNotNull(renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(block, renderType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.bootstrap.definitions;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityDefinition {
|
||||
|
||||
// To be notified when a Block declares that it uses this block entity
|
||||
private final Consumer<Block> addBlockListener;
|
||||
|
||||
public TileEntityDefinition(Consumer<Block> addBlockListener) {
|
||||
this.addBlockListener = addBlockListener;
|
||||
}
|
||||
|
||||
public void addBlock(Block block) {
|
||||
this.addBlockListener.accept(block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.capabilities;
|
||||
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.api.storage.IStorageMonitorableAccessor;
|
||||
|
||||
/**
|
||||
* Utility class that holds various capabilities, both by AE2 and other Mods.
|
||||
*/
|
||||
public final class Capabilities {
|
||||
|
||||
private Capabilities() {
|
||||
}
|
||||
|
||||
public static Capability<IStorageMonitorableAccessor> STORAGE_MONITORABLE_ACCESSOR;
|
||||
|
||||
public static Capability<ISpatialDimension> SPATIAL_DIMENSION;
|
||||
|
||||
public static Capability<IEnergyStorage> FORGE_ENERGY;
|
||||
|
||||
/**
|
||||
* Register AE2 provided capabilities.
|
||||
*/
|
||||
public static void register() {
|
||||
CapabilityManager.INSTANCE.register(IStorageMonitorableAccessor.class, createNullStorage(),
|
||||
NullMENetworkAccessor::new);
|
||||
CapabilityManager.INSTANCE.register(ISpatialDimension.class, createNullStorage(), NullSpatialDimension::new);
|
||||
}
|
||||
|
||||
@CapabilityInject(IStorageMonitorableAccessor.class)
|
||||
private static void capIStorageMonitorableAccessorRegistered(Capability<IStorageMonitorableAccessor> cap) {
|
||||
STORAGE_MONITORABLE_ACCESSOR = cap;
|
||||
}
|
||||
|
||||
@CapabilityInject(ISpatialDimension.class)
|
||||
private static void capISpatialDimensionRegistered(Capability<ISpatialDimension> cap) {
|
||||
SPATIAL_DIMENSION = cap;
|
||||
}
|
||||
|
||||
@CapabilityInject(IEnergyStorage.class)
|
||||
private static void capIEnergyStorageRegistered(Capability<IEnergyStorage> cap) {
|
||||
FORGE_ENERGY = cap;
|
||||
}
|
||||
|
||||
// Create a storage implementation that does not do anything
|
||||
private static <T> Capability.IStorage<T> createNullStorage() {
|
||||
return new Capability.IStorage<T>() {
|
||||
@Override
|
||||
public INBT writeNBT(Capability<T> capability, T instance, Direction side) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<T> capability, T instance, Direction side, INBT nbt) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.capabilities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
|
||||
class NullSpatialDimension implements ISpatialDimension {
|
||||
@Override
|
||||
public DimensionType createNewCellDimension(BlockPos size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCellDimension(DimensionType cellStorageId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellDimensionOrigin(DimensionType cellStorageId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellDimensionSize(DimensionType cellDim) {
|
||||
return BlockPos.ORIGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCellDimensionTooltip(DimensionType cellDim, List<Text> tooltip) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld(DimensionType cellStorageId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellDimension(DimensionType cellDimID) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
package appeng.client;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public enum ActionKey {
|
||||
TOGGLE_FOCUS(GLFW.GLFW_KEY_TAB);
|
||||
|
||||
private final int defaultKey;
|
||||
|
||||
private ActionKey(int defaultKey) {
|
||||
this.defaultKey = defaultKey;
|
||||
}
|
||||
|
||||
public String getTranslationKey() {
|
||||
return "key." + this.name().toLowerCase() + ".desc";
|
||||
}
|
||||
|
||||
public int getDefaultKey() {
|
||||
return this.defaultKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package appeng.client;
|
||||
|
||||
import appeng.api.parts.CableRenderMode;
|
||||
import appeng.bootstrap.ModelsReloadCallback;
|
||||
import appeng.bootstrap.components.IItemColorRegistrationComponent;
|
||||
import appeng.bootstrap.components.IModelBakeComponent;
|
||||
import appeng.client.render.cablebus.CableBusModelLoader;
|
||||
import appeng.client.render.effects.*;
|
||||
import appeng.client.render.tesr.SkyChestTESR;
|
||||
import appeng.core.Api;
|
||||
import appeng.core.ApiDefinitions;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.AppEngBase;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
import appeng.core.sync.network.ClientNetworkHandler;
|
||||
import appeng.entity.*;
|
||||
import appeng.hooks.ClientTickHandler;
|
||||
import appeng.util.Platform;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
|
||||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.entity.ItemEntityRenderer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class AppEngClient extends AppEngBase {
|
||||
|
||||
private final MinecraftClient client;
|
||||
|
||||
private final ClientNetworkHandler networkHandler;
|
||||
|
||||
private final ClientTickHandler tickHandler;
|
||||
|
||||
public static AppEngClient instance() {
|
||||
return (AppEngClient) AppEng.instance();
|
||||
}
|
||||
|
||||
public AppEngClient() {
|
||||
super();
|
||||
|
||||
client = MinecraftClient.getInstance();
|
||||
networkHandler = new ClientNetworkHandler();
|
||||
tickHandler = new ClientTickHandler();
|
||||
|
||||
ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
|
||||
|
||||
registerModelProviders();
|
||||
registerParticleRenderers();
|
||||
registerEntityRenderers();
|
||||
registerItemColors();
|
||||
registerTextures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
IntegratedServer server = client.getServer();
|
||||
if (server != null) {
|
||||
return server;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No server is currently running.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<? extends PlayerEntity> getPlayers() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEffect(EffectType effect, World world, double posX, double posY, double posZ, Object extra) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAddParticles(Random r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HitResult getRTR() {
|
||||
return client.crosshairTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableRenderMode getRenderMode() {
|
||||
if (Platform.isServer()) {
|
||||
return super.getRenderMode();
|
||||
}
|
||||
|
||||
final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
final PlayerEntity player = mc.player;
|
||||
|
||||
return this.renderModeForPlayer(player);
|
||||
}
|
||||
|
||||
public void triggerUpdates() {
|
||||
if (client.player == null || client.world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PlayerEntity player = client.player;
|
||||
|
||||
final int x = (int) player.getX();
|
||||
final int y = (int) player.getY();
|
||||
final int z = (int) player.getZ();
|
||||
|
||||
final int range = 16 * 16;
|
||||
|
||||
client.worldRenderer.scheduleBlockRenders(x - range, y - range, z - range, x + range, y + range,
|
||||
z + range);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRenderMode(PlayerEntity player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionKey(@Nonnull ActionKey key, InputUtil.Key input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void registerParticleRenderers() {
|
||||
ParticleFactoryRegistry particles = ParticleFactoryRegistry.getInstance();
|
||||
particles.register(ParticleTypes.CHARGED_ORE, ChargedOreFX.Factory::new);
|
||||
particles.register(ParticleTypes.CRAFTING, CraftingFx.Factory::new);
|
||||
particles.register(ParticleTypes.ENERGY, EnergyFx.Factory::new);
|
||||
particles.register(ParticleTypes.LIGHTNING_ARC, LightningArcFX.Factory::new);
|
||||
particles.register(ParticleTypes.LIGHTNING, LightningFX.Factory::new);
|
||||
particles.register(ParticleTypes.MATTER_CANNON, MatterCannonFX.Factory::new);
|
||||
particles.register(ParticleTypes.VIBRANT, VibrantFX.Factory::new);
|
||||
}
|
||||
|
||||
protected void registerEntityRenderers() {
|
||||
EntityRendererRegistry registry = EntityRendererRegistry.INSTANCE;
|
||||
|
||||
registry.register(TinyTNTPrimedEntity.TYPE, (dispatcher, context) -> new TinyTNTPrimedRenderer(dispatcher));
|
||||
|
||||
EntityRendererRegistry.Factory itemEntityFactory = (dispatcher, context) -> new ItemEntityRenderer(dispatcher, context.getItemRenderer());
|
||||
registry.register(SingularityEntity.TYPE, itemEntityFactory);
|
||||
registry.register(GrowingCrystalEntity.TYPE, itemEntityFactory);
|
||||
registry.register(ChargedQuartzEntity.TYPE, itemEntityFactory);
|
||||
}
|
||||
|
||||
protected void registerItemColors() {
|
||||
// TODO: Do not use the internal API
|
||||
final ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||
definitions.getRegistry().getBootstrapComponents(IItemColorRegistrationComponent.class)
|
||||
.forEachRemaining(IItemColorRegistrationComponent::register);
|
||||
}
|
||||
|
||||
protected void onModelsReloaded(Map<Identifier, BakedModel> loadedModels) {
|
||||
// TODO: Do not use the internal API
|
||||
final ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||
definitions.getRegistry().getBootstrapComponents(IModelBakeComponent.class)
|
||||
.forEachRemaining(c -> c.onModelsReloaded(loadedModels));
|
||||
}
|
||||
|
||||
public void registerTextures() {
|
||||
// FIXME FABRIC InscriberTESR.registerTexture();
|
||||
Stream<Collection<SpriteIdentifier>> sprites = Stream.of(
|
||||
SkyChestTESR.SPRITES
|
||||
);
|
||||
|
||||
// Group every needed sprite by atlas, since every atlas has their own event
|
||||
Map<Identifier, List<SpriteIdentifier>> groupedByAtlas = sprites.flatMap(Collection::stream)
|
||||
.collect(Collectors.groupingBy(SpriteIdentifier::getAtlasId));
|
||||
|
||||
// Register to the stitch event for each atlas
|
||||
for (Map.Entry<Identifier, List<SpriteIdentifier>> entry : groupedByAtlas.entrySet()) {
|
||||
ClientSpriteRegistryCallback.event(entry.getKey())
|
||||
.register((spriteAtlasTexture, registry) -> {
|
||||
for (SpriteIdentifier spriteIdentifier : entry.getValue()) {
|
||||
registry.register(spriteIdentifier.getTextureId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void registerModelProviders() {
|
||||
|
||||
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> new CableBusModelLoader((PartModels) Api.INSTANCE.registries().partModels()));
|
||||
|
||||
// FIXME FABRIC addBuiltInModel("glass", GlassModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("sky_compass", SkyCompassModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("dummy_fluid_item", DummyFluidItemModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("memory_card", MemoryCardModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("biometric_card", BiometricCardModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("drive", DriveModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("color_applicator", ColorApplicatorModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("spatial_pylon", SpatialPylonModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("paint_splotches", PaintSplotchesModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("quantum_bridge_formed", QnbFormedModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("p2p_tunnel_frequency", P2PTunnelFrequencyModel::new);
|
||||
// FIXME FABRIC addBuiltInModel("facade", FacadeItemModel::new);
|
||||
// FIXME FABRIC ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "encoded_pattern"),
|
||||
// FIXME FABRIC EncodedPatternModelLoader.INSTANCE);
|
||||
// FIXME FABRIC ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "part_plane"),
|
||||
// FIXME FABRIC PlaneModelLoader.INSTANCE);
|
||||
// FIXME FABRIC ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "crafting_cube"),
|
||||
// FIXME FABRIC CraftingCubeModelLoader.INSTANCE);
|
||||
// FIXME FABRIC ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "uvlightmap"), UVLModelLoader.INSTANCE);
|
||||
// FIXME FABRIC ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "cable_bus"),
|
||||
// FIXME FABRIC new CableBusModelLoader());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
import appeng.api.parts.CableRenderMode;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.render.effects.*;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.helpers.IMouseWheelItem;
|
||||
import appeng.server.ServerHelper;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ClientHelper extends ServerHelper {
|
||||
private final static String KEY_CATEGORY = "key.appliedenergistics2.category";
|
||||
|
||||
private final EnumMap<ActionKey, KeyBinding> bindings = new EnumMap<>(ActionKey.class);
|
||||
|
||||
public void clientInit() {
|
||||
MinecraftForge.EVENT_BUS.addListener(this::postPlayerRender);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::wheelEvent);
|
||||
|
||||
for (ActionKey key : ActionKey.values()) {
|
||||
final KeyBinding binding = new KeyBinding(key.getTranslationKey(), key.getDefaultKey(), KEY_CATEGORY);
|
||||
ClientRegistry.registerKeyBinding(binding);
|
||||
this.bindings.put(key, binding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTileEntitySpecialRenderer(final Class<? extends BlockEntity> tile, final AEBaseBlock blk) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends PlayerEntity> getPlayers() {
|
||||
if (Platform.isClient()) {
|
||||
return Collections.singletonList(MinecraftClient.getInstance().player);
|
||||
} else {
|
||||
return super.getPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Instead of doing a custom packet and this dispatcher, we can use the
|
||||
// vanilla particle system
|
||||
@Override
|
||||
public void spawnEffect(final EffectType effect, final World world, final double posX, final double posY,
|
||||
final double posZ, final Object o) {
|
||||
if (AEConfig.instance().isEnableEffects()) {
|
||||
switch (effect) {
|
||||
case Vibrant:
|
||||
this.spawnVibrant(world, posX, posY, posZ);
|
||||
return;
|
||||
case Energy:
|
||||
this.spawnEnergy(world, posX, posY, posZ);
|
||||
return;
|
||||
case LightningArc:
|
||||
this.spawnLightningArc(world, posX, posY, posZ, (Vec3d) o);
|
||||
return;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAddParticles(final Random r) {
|
||||
switch (MinecraftClient.getInstance().options.particles) {
|
||||
default:
|
||||
case ALL:
|
||||
return true;
|
||||
case DECREASED:
|
||||
return r.nextBoolean();
|
||||
case MINIMAL:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
}
|
||||
|
||||
|
||||
private void postPlayerRender(final RenderLivingEvent.Pre p) {
|
||||
// FIXME final PlayerColor player = TickHandler.INSTANCE.getPlayerColors().get( p.getEntity().getEntityId() );
|
||||
// FIXME if( player != null )
|
||||
// FIXME {
|
||||
// FIXME final AEColor col = player.myColor;
|
||||
// FIXME final float r = 0xff & ( col.mediumVariant >> 16 );
|
||||
// FIXME final float g = 0xff & ( col.mediumVariant >> 8 );
|
||||
// FIXME final float b = 0xff & ( col.mediumVariant );
|
||||
// FIXME // FIXME: This is most certainly not going to work!
|
||||
// FIXME GlStateManager.color4f( r / 255.0f, g / 255.0f, b / 255.0f, 1.0f );
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
private void spawnVibrant(final World w, final double x, final double y, final double z) {
|
||||
if (AppEng.instance().shouldAddParticles(Platform.getRandom())) {
|
||||
final double d0 = (Platform.getRandomFloat() - 0.5F) * 0.26D;
|
||||
final double d1 = (Platform.getRandomFloat() - 0.5F) * 0.26D;
|
||||
final double d2 = (Platform.getRandomFloat() - 0.5F) * 0.26D;
|
||||
|
||||
MinecraftClient.getInstance().particleManager.addParticle(ParticleTypes.VIBRANT, x + d0, y + d1, z + d2, 0.0D, 0.0D,
|
||||
0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnEnergy(final World w, final double posX, final double posY, final double posZ) {
|
||||
final float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
|
||||
final float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
|
||||
final float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
|
||||
|
||||
MinecraftClient.getInstance().particleManager.addParticle(EnergyParticleData.FOR_BLOCK, posX + x, posY + y, posZ + z,
|
||||
-x * 0.1, -y * 0.1, -z * 0.1);
|
||||
}
|
||||
|
||||
private void spawnLightningArc(final World world, final double posX, final double posY, final double posZ,
|
||||
final Vec3d second) {
|
||||
final LightningFX fx = new LightningArcFX(world, posX, posY, posZ, second.x, second.y, second.z, 0.0f, 0.0f,
|
||||
0.0f);
|
||||
MinecraftClient.getInstance().particleManager.addParticle(fx);
|
||||
}
|
||||
|
||||
private void wheelEvent(final InputEvent.MouseScrollEvent me) {
|
||||
if (me.getScrollDelta() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
final PlayerEntity player = mc.player;
|
||||
if (player.isInSneakingPose()) {
|
||||
final boolean mainHand = player.getStackInHand(Hand.MAIN_HAND).getItem() instanceof IMouseWheelItem;
|
||||
final boolean offHand = player.getStackInHand(Hand.OFF_HAND).getItem() instanceof IMouseWheelItem;
|
||||
|
||||
if (mainHand || offHand) {
|
||||
NetworkHandler.instance()
|
||||
.sendToServer(new ConfigValuePacket("Item", me.getScrollDelta() > 0 ? "WheelUp" : "WheelDown"));
|
||||
me.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionKey(ActionKey key, InputUtil.Key pressedKey) {
|
||||
return this.bindings.get(key).isActiveAndMatches(pressedKey);
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -16,11 +16,8 @@
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.spatial;
|
||||
package appeng.client;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface ISpatialVisitor {
|
||||
|
||||
void visit(BlockPos pos);
|
||||
public enum EffectType {
|
||||
Energy, Vibrant, LightningArc
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.ButtonToolTips;
|
||||
|
||||
public abstract class AEBaseMEScreen<T extends AEBaseContainer> extends AEBaseScreen<T> {
|
||||
|
||||
public AEBaseMEScreen(T container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderTooltip(final ItemStack stack, final int x, final int y) {
|
||||
final Slot s = this.getSlot(x, y);
|
||||
|
||||
if (s instanceof SlotME && !stack.isEmpty()) {
|
||||
final int bigNumber = AEConfig.instance().isUseLargeFonts() ? 999 : 9999;
|
||||
|
||||
IAEItemStack myStack = null;
|
||||
final List<String> currentToolTip = this.getTooltipFromItem(stack);
|
||||
|
||||
try {
|
||||
final SlotME theSlotField = (SlotME) s;
|
||||
myStack = theSlotField.getAEStack();
|
||||
} catch (final Throwable ignore) {
|
||||
}
|
||||
|
||||
if (myStack != null) {
|
||||
if (myStack.getStackSize() > bigNumber || (myStack.getStackSize() > 1 && stack.isDamaged())) {
|
||||
final String local = ButtonToolTips.ItemsStored.getLocal();
|
||||
final String formattedAmount = NumberFormat.getNumberInstance(Locale.US)
|
||||
.format(myStack.getStackSize());
|
||||
final String format = String.format(local, formattedAmount);
|
||||
|
||||
currentToolTip.add(Formatting.GRAY + format);
|
||||
}
|
||||
|
||||
if (myStack.getCountRequestable() > 0) {
|
||||
final String local = ButtonToolTips.ItemsRequestable.getLocal();
|
||||
final String formattedAmount = NumberFormat.getNumberInstance(Locale.US)
|
||||
.format(myStack.getCountRequestable());
|
||||
final String format = String.format(local, formattedAmount);
|
||||
|
||||
currentToolTip.add(format);
|
||||
}
|
||||
this.renderTooltip(currentToolTip, x, y, this.font);
|
||||
|
||||
return;
|
||||
} else if (stack.getCount() > bigNumber) {
|
||||
final String local = ButtonToolTips.ItemsStored.getLocal();
|
||||
final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(stack.getCount());
|
||||
final String format = String.format(local, formattedAmount);
|
||||
|
||||
currentToolTip.add(Formatting.GRAY + format);
|
||||
|
||||
this.renderTooltip(currentToolTip, x, y, this.font);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.renderTooltip(stack, x, y);
|
||||
}
|
||||
}
|
||||
@@ -1,785 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.widgets.CustomSlotWidget;
|
||||
import appeng.client.gui.widgets.ITooltip;
|
||||
import appeng.client.gui.widgets.Scrollbar;
|
||||
import appeng.client.me.InternalSlotME;
|
||||
import appeng.client.me.SlotDisconnected;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.client.render.StackSizeRenderer;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.AppEngCraftingSlot;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.AppEngSlot.CalculatedValidity;
|
||||
import appeng.container.slot.CraftingTermSlot;
|
||||
import appeng.container.slot.DisabledSlot;
|
||||
import appeng.container.slot.FakeSlot;
|
||||
import appeng.container.slot.IOptionalSlot;
|
||||
import appeng.container.slot.InaccessibleSlot;
|
||||
import appeng.container.slot.OutputSlot;
|
||||
import appeng.container.slot.PatternTermSlot;
|
||||
import appeng.container.slot.RestrictedInputSlot;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.InventoryActionPacket;
|
||||
import appeng.core.sync.packets.SwapSlotsPacket;
|
||||
import appeng.fluids.client.render.FluidStackSizeRenderer;
|
||||
import appeng.fluids.container.slots.IMEFluidSlot;
|
||||
import appeng.helpers.InventoryAction;
|
||||
|
||||
public abstract class AEBaseScreen<T extends AEBaseContainer> extends ContainerScreen<T> {
|
||||
private final List<InternalSlotME> meSlots = new ArrayList<>();
|
||||
// drag y
|
||||
private final Set<Slot> drag_click = new HashSet<>();
|
||||
private final StackSizeRenderer stackSizeRenderer = new StackSizeRenderer();
|
||||
private final FluidStackSizeRenderer fluidStackSizeRenderer = new FluidStackSizeRenderer();
|
||||
private Scrollbar myScrollBar = null;
|
||||
private boolean disableShiftClick = false;
|
||||
private Stopwatch dbl_clickTimer = Stopwatch.createStarted();
|
||||
private ItemStack dbl_whichItem = ItemStack.EMPTY;
|
||||
private Slot bl_clicked;
|
||||
protected final List<CustomSlotWidget> guiSlots = new ArrayList<>();
|
||||
|
||||
public AEBaseScreen(T container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
slots.removeIf(slot -> slot instanceof SlotME);
|
||||
|
||||
for (final InternalSlotME me : this.meSlots) {
|
||||
slots.add(new SlotME(me));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Slot> getInventorySlots() {
|
||||
return this.container.inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.renderBackground();
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translatef(this.guiLeft, this.guiTop, 0.0F);
|
||||
RenderSystem.enableDepthTest();
|
||||
for (final CustomSlotWidget c : this.guiSlots) {
|
||||
this.drawGuiSlot(c, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
RenderSystem.disableDepthTest();
|
||||
for (final CustomSlotWidget c : this.guiSlots) {
|
||||
this.drawTooltip(c, mouseX - this.guiLeft, mouseY - this.guiTop);
|
||||
}
|
||||
RenderSystem.popMatrix();
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
this.renderHoveredToolTip(mouseX, mouseY);
|
||||
|
||||
for (final Object c : this.buttons) {
|
||||
if (c instanceof ITooltip) {
|
||||
this.drawTooltip((ITooltip) c, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawGuiSlot(CustomSlotWidget slot, int mouseX, int mouseY, float partialTicks) {
|
||||
if (slot.isSlotEnabled()) {
|
||||
final int left = slot.xPos();
|
||||
final int top = slot.yPos();
|
||||
final int right = left + slot.getWidth();
|
||||
final int bottom = top + slot.getHeight();
|
||||
|
||||
slot.drawContent(getMinecraft(), mouseX, mouseY, partialTicks);
|
||||
|
||||
if (this.isPointInRegion(left, top, slot.getWidth(), slot.getHeight(), mouseX, mouseY)
|
||||
&& slot.canClick(getPlayer())) {
|
||||
RenderSystem.colorMask(true, true, true, false);
|
||||
this.fillGradient(left, top, right, bottom, -2130706433, -2130706433);
|
||||
RenderSystem.colorMask(true, true, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTooltip(ITooltip tooltip, int mouseX, int mouseY) {
|
||||
final int x = tooltip.xPos(); // ((GuiImgButton) c).x;
|
||||
int y = tooltip.yPos(); // ((GuiImgButton) c).y;
|
||||
|
||||
if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) {
|
||||
if (y < mouseY && y + tooltip.getHeight() > mouseY) {
|
||||
if (y < 15) {
|
||||
y = 15;
|
||||
}
|
||||
|
||||
final String msg = tooltip.getMessage();
|
||||
if (msg != null) {
|
||||
this.drawTooltip(x + 11, y + 4, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTooltip(int x, int y, String message) {
|
||||
String[] lines = message.split("\n");
|
||||
this.drawTooltip(x, y, Arrays.asList(lines));
|
||||
}
|
||||
|
||||
protected void drawTooltip(int x, int y, List<String> lines) {
|
||||
if (lines.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For an explanation of the formatting codes, see
|
||||
// http://minecraft.gamepedia.com/Formatting_codes
|
||||
lines = Lists.newArrayList(lines); // Make a copy
|
||||
|
||||
// Make the first line white
|
||||
lines.set(0, Formatting.WHITE + lines.get(0));
|
||||
|
||||
// All lines after the first are colored gray
|
||||
for (int i = 1; i < lines.size(); i++) {
|
||||
lines.set(i, Formatting.GRAY + lines.get(i));
|
||||
}
|
||||
|
||||
this.renderTooltip(lines, x, y, this.font);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void drawGuiContainerForegroundLayer(final int x, final int y) {
|
||||
final int ox = this.guiLeft; // (width - xSize) / 2;
|
||||
final int oy = this.guiTop; // (height - ySize) / 2;
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
if (this.getScrollBar() != null) {
|
||||
this.getScrollBar().draw(this);
|
||||
}
|
||||
|
||||
this.drawFG(ox, oy, x, y);
|
||||
}
|
||||
|
||||
public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY);
|
||||
|
||||
@Override
|
||||
protected final void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) {
|
||||
final int ox = this.guiLeft; // (width - xSize) / 2;
|
||||
final int oy = this.guiTop; // (height - ySize) / 2;
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.drawBG(ox, oy, x, y, f);
|
||||
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
for (final Slot slot : slots) {
|
||||
if (slot instanceof IOptionalSlot) {
|
||||
final IOptionalSlot optionalSlot = (IOptionalSlot) slot;
|
||||
if (optionalSlot.isRenderDisabled()) {
|
||||
final AppEngSlot aeSlot = (AppEngSlot) slot;
|
||||
if (aeSlot.isSlotEnabled()) {
|
||||
GuiUtils.drawTexturedModalRect(ox + aeSlot.xPos - 1, oy + aeSlot.yPos - 1,
|
||||
optionalSlot.getSourceX() - 1, optionalSlot.getSourceY() - 1, 18, 18, getBlitOffset());
|
||||
} else {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.4F);
|
||||
RenderSystem.enableBlend();
|
||||
GuiUtils.drawTexturedModalRect(ox + aeSlot.xPos - 1, oy + aeSlot.yPos - 1,
|
||||
optionalSlot.getSourceX() - 1, optionalSlot.getSourceY() - 1, 18, 18, getBlitOffset());
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final CustomSlotWidget slot : this.guiSlots) {
|
||||
slot.drawBackground(ox, oy, getBlitOffset());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(final double xCoord, final double yCoord, final int btn) {
|
||||
this.drag_click.clear();
|
||||
|
||||
if (btn == 1) {
|
||||
for (final Object o : this.buttons) {
|
||||
final Widget widget = (Widget) o;
|
||||
if (widget.isMouseOver(xCoord, yCoord)) {
|
||||
return super.mouseClicked(xCoord, yCoord, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (CustomSlotWidget slot : this.guiSlots) {
|
||||
if (this.isPointInRegion(slot.xPos(), slot.yPos(), slot.getWidth(), slot.getHeight(), xCoord, yCoord)
|
||||
&& slot.canClick(getPlayer())) {
|
||||
slot.slotClicked(getPlayer().inventory.getItemStack(), btn);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getScrollBar() != null) {
|
||||
this.getScrollBar().click(xCoord - this.guiLeft, yCoord - this.guiTop);
|
||||
}
|
||||
|
||||
return super.mouseClicked(xCoord, yCoord, btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
|
||||
final Slot slot = this.getSlot((int) mouseX, (int) mouseY);
|
||||
final ItemStack itemstack = getPlayer().inventory.getItemStack();
|
||||
|
||||
if (this.getScrollBar() != null) {
|
||||
// FIXME: Coordinate system of mouseX/mouseY is unclear
|
||||
this.getScrollBar().click((int) mouseX - this.guiLeft, (int) mouseY - this.guiTop);
|
||||
}
|
||||
|
||||
if (slot instanceof FakeSlot && !itemstack.isEmpty()) {
|
||||
this.drag_click.add(slot);
|
||||
if (this.drag_click.size() > 1) {
|
||||
for (final Slot dr : this.drag_click) {
|
||||
final InventoryActionPacket p = new InventoryActionPacket(
|
||||
mouseButton == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE,
|
||||
dr.slotNumber, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.mouseDragged(mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 1.9.4 aftermath - Whole ClickType thing, to be checked.
|
||||
@Override
|
||||
protected void handleMouseClick(final Slot slot, final int slotIdx, final int mouseButton,
|
||||
final ClickType clickType) {
|
||||
final PlayerEntity player = getPlayer();
|
||||
|
||||
if (slot instanceof FakeSlot) {
|
||||
final InventoryAction action = mouseButton == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE
|
||||
: InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
|
||||
if (this.drag_click.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final InventoryActionPacket p = new InventoryActionPacket(action, slotIdx, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (slot instanceof PatternTermSlot) {
|
||||
if (mouseButton == 6) {
|
||||
return; // prevent weird double clicks..
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(((PatternTermSlot) slot).getRequest(hasShiftDown()));
|
||||
} else if (slot instanceof CraftingTermSlot) {
|
||||
if (mouseButton == 6) {
|
||||
return; // prevent weird double clicks..
|
||||
}
|
||||
|
||||
InventoryAction action;
|
||||
if (hasShiftDown()) {
|
||||
action = InventoryAction.CRAFT_SHIFT;
|
||||
} else {
|
||||
// Craft stack on right-click, craft single on left-click
|
||||
action = (mouseButton == 1) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
|
||||
}
|
||||
|
||||
final InventoryActionPacket p = new InventoryActionPacket(action, slotIdx, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (InputMappings.isKeyDown(MinecraftClient.getInstance().getMainWindow().getHandle(), GLFW.GLFW_KEY_SPACE)) {
|
||||
if (this.enableSpaceClicking()) {
|
||||
IAEItemStack stack = null;
|
||||
if (slot instanceof SlotME) {
|
||||
stack = ((SlotME) slot).getAEStack();
|
||||
}
|
||||
|
||||
int slotNum = this.getInventorySlots().size();
|
||||
|
||||
if (!(slot instanceof SlotME) && slot != null) {
|
||||
slotNum = slot.slotNumber;
|
||||
}
|
||||
|
||||
((AEBaseContainer) this.container).setTargetStack(stack);
|
||||
final InventoryActionPacket p = new InventoryActionPacket(InventoryAction.MOVE_REGION, slotNum, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (slot instanceof SlotDisconnected) {
|
||||
InventoryAction action = null;
|
||||
|
||||
switch (clickType) {
|
||||
case PICKUP: // pickup / set-down.
|
||||
action = (mouseButton == 1) ? InventoryAction.SPLIT_OR_PLACE_SINGLE
|
||||
: InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
break;
|
||||
case QUICK_MOVE:
|
||||
action = (mouseButton == 1) ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
|
||||
break;
|
||||
|
||||
case CLONE: // creative dupe:
|
||||
|
||||
if (player.abilities.isCreativeMode) {
|
||||
action = InventoryAction.CREATIVE_DUPLICATE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
case THROW: // drop item:
|
||||
}
|
||||
|
||||
if (action != null) {
|
||||
final InventoryActionPacket p = new InventoryActionPacket(action, slot.getSlotIndex(),
|
||||
((SlotDisconnected) slot).getSlot().getId());
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (slot instanceof SlotME) {
|
||||
InventoryAction action = null;
|
||||
IAEItemStack stack = null;
|
||||
|
||||
switch (clickType) {
|
||||
case PICKUP: // pickup / set-down.
|
||||
action = (mouseButton == 1) ? InventoryAction.SPLIT_OR_PLACE_SINGLE
|
||||
: InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
stack = ((SlotME) slot).getAEStack();
|
||||
|
||||
if (stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0
|
||||
&& player.inventory.getItemStack().isEmpty()) {
|
||||
action = InventoryAction.AUTO_CRAFT;
|
||||
}
|
||||
|
||||
break;
|
||||
case QUICK_MOVE:
|
||||
action = (mouseButton == 1) ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
|
||||
stack = ((SlotME) slot).getAEStack();
|
||||
break;
|
||||
|
||||
case CLONE: // creative dupe:
|
||||
|
||||
stack = ((SlotME) slot).getAEStack();
|
||||
if (stack != null && stack.isCraftable()) {
|
||||
action = InventoryAction.AUTO_CRAFT;
|
||||
} else if (player.abilities.isCreativeMode) {
|
||||
final IAEItemStack slotItem = ((SlotME) slot).getAEStack();
|
||||
if (slotItem != null) {
|
||||
action = InventoryAction.CREATIVE_DUPLICATE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
case THROW: // drop item:
|
||||
}
|
||||
|
||||
if (action != null) {
|
||||
this.container.setTargetStack(stack);
|
||||
final InventoryActionPacket p = new InventoryActionPacket(action, this.getInventorySlots().size(), 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.disableShiftClick && hasShiftDown() && mouseButton == 0) {
|
||||
this.disableShiftClick = true;
|
||||
|
||||
if (this.dbl_whichItem.isEmpty() || this.bl_clicked != slot
|
||||
|| this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 250) {
|
||||
// some simple double click logic.
|
||||
this.bl_clicked = slot;
|
||||
this.dbl_clickTimer = Stopwatch.createStarted();
|
||||
if (slot != null) {
|
||||
this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : ItemStack.EMPTY;
|
||||
} else {
|
||||
this.dbl_whichItem = ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.dbl_whichItem.isEmpty()) {
|
||||
// a replica of the weird broken vanilla feature.
|
||||
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
for (final Slot inventorySlot : slots) {
|
||||
if (inventorySlot != null && inventorySlot.canTakeStack(getPlayer()) && inventorySlot.getHasStack()
|
||||
&& inventorySlot.isSameInventory(slot)
|
||||
&& Container.canAddItemToSlot(inventorySlot, this.dbl_whichItem, true)) {
|
||||
this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, 0, ClickType.QUICK_MOVE);
|
||||
}
|
||||
}
|
||||
this.dbl_whichItem = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
this.disableShiftClick = false;
|
||||
}
|
||||
|
||||
super.handleMouseClick(slot, slotIdx, mouseButton, clickType);
|
||||
}
|
||||
|
||||
protected boolean func_195363_d(int keyCode, int scanCode) {
|
||||
return checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode));
|
||||
}
|
||||
|
||||
protected ClientPlayerEntity getPlayer() {
|
||||
// Our UIs are usually not opened when not in-game, so this should not be a
|
||||
// problem
|
||||
return Preconditions.checkNotNull(getMinecraft().player);
|
||||
}
|
||||
|
||||
protected boolean checkHotbarKeys(final InputUtil.Key input) {
|
||||
final Slot theSlot = this.getSlotUnderMouse();
|
||||
|
||||
if (getPlayer().inventory.getItemStack().isEmpty() && theSlot != null) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
if (getMinecraft().options.keyBindsHotbar[j].isActiveAndMatches(input)) {
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
for (final Slot s : slots) {
|
||||
if (s.getSlotIndex() == j && s.inventory == ((AEBaseContainer) this.container).getPlayerInv()) {
|
||||
if (!s.canTakeStack(((AEBaseContainer) this.container).getPlayerInv().player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (theSlot.getSlotStackLimit() == 64) {
|
||||
this.handleMouseClick(theSlot, theSlot.slotNumber, j, ClickType.SWAP);
|
||||
return true;
|
||||
} else {
|
||||
for (final Slot s : slots) {
|
||||
if (s.getSlotIndex() == j
|
||||
&& s.inventory == ((AEBaseContainer) this.container).getPlayerInv()) {
|
||||
NetworkHandler.instance()
|
||||
.sendToServer(new SwapSlotsPacket(s.slotNumber, theSlot.slotNumber));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
super.removed();
|
||||
}
|
||||
|
||||
protected Slot getSlot(final int mouseX, final int mouseY) {
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
for (final Slot slot : slots) {
|
||||
// isPointInRegion
|
||||
if (this.isPointInRegion(slot.xPos, slot.yPos, 16, 16, mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double wheelDelta) {
|
||||
if (wheelDelta != 0 && hasShiftDown()) {
|
||||
this.mouseWheelEvent(x, y, wheelDelta / Math.abs(wheelDelta));
|
||||
return true;
|
||||
} else if (wheelDelta != 0 && this.getScrollBar() != null) {
|
||||
this.getScrollBar().wheel(wheelDelta);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void mouseWheelEvent(final double x, final double y, final double wheel) {
|
||||
final Slot slot = this.getSlot((int) x, (int) y);
|
||||
if (slot instanceof SlotME) {
|
||||
final IAEItemStack item = ((SlotME) slot).getAEStack();
|
||||
if (item != null) {
|
||||
((AEBaseContainer) this.container).setTargetStack(item);
|
||||
final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP;
|
||||
final int times = (int) Math.abs(wheel);
|
||||
final int inventorySize = this.getInventorySlots().size();
|
||||
for (int h = 0; h < times; h++) {
|
||||
final InventoryActionPacket p = new InventoryActionPacket(direction, inventorySize, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean enableSpaceClicking() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void bindTexture(final String base, final String file) {
|
||||
final Identifier loc = new Identifier(base, "textures/" + file);
|
||||
getMinecraft().getTextureManager().bindTexture(loc);
|
||||
}
|
||||
|
||||
protected void drawItem(final int x, final int y, final ItemStack is) {
|
||||
this.itemRenderer.zLevel = 100.0F;
|
||||
|
||||
// FIXME I dont think this is needed anymore...
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
this.itemRenderer.renderItemAndEffectIntoGUI(is, x, y);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
this.itemRenderer.zLevel = 0.0F;
|
||||
}
|
||||
|
||||
protected String getGuiDisplayName(final String in) {
|
||||
return this.hasCustomInventoryName() ? this.getInventoryName() : in;
|
||||
}
|
||||
|
||||
private boolean hasCustomInventoryName() {
|
||||
return this.container.getCustomName() != null;
|
||||
}
|
||||
|
||||
private String getInventoryName() {
|
||||
return this.container.getCustomName();
|
||||
}
|
||||
|
||||
/**
|
||||
* This overrides the base-class method through some access transformer
|
||||
* hackery...
|
||||
*/
|
||||
@Override
|
||||
public void drawSlot(Slot s) {
|
||||
if (s instanceof SlotME) {
|
||||
|
||||
try {
|
||||
if (!this.isPowered()) {
|
||||
fill(s.xPos, s.yPos, 16 + s.xPos, 16 + s.yPos, 0x66111111);
|
||||
}
|
||||
|
||||
// Annoying but easier than trying to splice into render item
|
||||
super.drawSlot(new Size1Slot((SlotME) s));
|
||||
|
||||
this.stackSizeRenderer.renderStackSize(this.font, ((SlotME) s).getAEStack(), s.xPos, s.yPos);
|
||||
|
||||
} catch (final Exception err) {
|
||||
AELog.warn("[AppEng] AE prevented crash while drawing slot: " + err.toString());
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (s instanceof IMEFluidSlot && ((IMEFluidSlot) s).shouldRenderAsFluid()) {
|
||||
final IMEFluidSlot slot = (IMEFluidSlot) s;
|
||||
final IAEFluidStack fs = slot.getAEFluidStack();
|
||||
|
||||
if (fs != null && this.isPowered()) {
|
||||
RenderSystem.disableBlend();
|
||||
final Fluid fluid = fs.getFluid();
|
||||
FluidAttributes fluidAttributes = fluid.getAttributes();
|
||||
bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
|
||||
Identifier fluidStillTexture = fluidAttributes.getStillTexture(fs.getFluidStack());
|
||||
final Sprite sprite = getMinecraft()
|
||||
.getAtlasSpriteGetter(SpriteAtlasTexture.BLOCK_ATLAS_TEX).apply(fluidStillTexture);
|
||||
|
||||
// Set color for dynamic fluids
|
||||
// Convert int color to RGB
|
||||
float red = (fluidAttributes.getColor() >> 16 & 255) / 255.0F;
|
||||
float green = (fluidAttributes.getColor() >> 8 & 255) / 255.0F;
|
||||
float blue = (fluidAttributes.getColor() & 255) / 255.0F;
|
||||
RenderSystem.color3f(red, green, blue);
|
||||
|
||||
blit(s.xPos, s.yPos, 0 /* FIXME: Validate this was previous the controls zindex */, 16, 16, sprite);
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
this.fluidStackSizeRenderer.renderStackSize(this.font, fs, s.xPos, s.yPos);
|
||||
} else if (!this.isPowered()) {
|
||||
fill(s.xPos, s.yPos, 16 + s.xPos, 16 + s.yPos, 0x66111111);
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
final ItemStack is = s.getStack();
|
||||
if (s instanceof AppEngSlot && (((AppEngSlot) s).renderIconWithItem() || is.isEmpty())
|
||||
&& (((AppEngSlot) s).shouldDisplay())) {
|
||||
final AppEngSlot aes = (AppEngSlot) s;
|
||||
if (aes.getIcon() >= 0) {
|
||||
this.bindTexture("guis/states.png");
|
||||
|
||||
try {
|
||||
final int uv_y = aes.getIcon() / 16;
|
||||
final int uv_x = aes.getIcon() - uv_y * 16;
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
final float par1 = aes.xPos;
|
||||
final float par2 = aes.yPos;
|
||||
final float par3 = uv_x * 16;
|
||||
final float par4 = uv_y * 16;
|
||||
|
||||
final Tessellator tessellator = Tessellator.getInstance();
|
||||
final BufferBuilder vb = tessellator.getBuffer();
|
||||
|
||||
vb.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEX_COLOR);
|
||||
|
||||
final float f1 = 0.00390625F;
|
||||
final float f = 0.00390625F;
|
||||
final float par6 = 16;
|
||||
vb.pos(par1 + 0, par2 + par6, getBlitOffset()).tex((par3 + 0) * f, (par4 + par6) * f1)
|
||||
.color(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()).endVertex();
|
||||
final float par5 = 16;
|
||||
vb.pos(par1 + par5, par2 + par6, getBlitOffset()).tex((par3 + par5) * f, (par4 + par6) * f1)
|
||||
.color(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()).endVertex();
|
||||
vb.pos(par1 + par5, par2 + 0, getBlitOffset()).tex((par3 + par5) * f, (par4 + 0) * f1)
|
||||
.color(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()).endVertex();
|
||||
vb.pos(par1 + 0, par2 + 0, getBlitOffset()).tex((par3 + 0) * f, (par4 + 0) * f1)
|
||||
.color(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()).endVertex();
|
||||
tessellator.draw();
|
||||
|
||||
} catch (final Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is.isEmpty() && s instanceof AppEngSlot) {
|
||||
AppEngSlot aeSlot = (AppEngSlot) s;
|
||||
if (aeSlot.getIsValid() == CalculatedValidity.NotAvailable) {
|
||||
boolean isValid = s.isItemValid(is) || s instanceof OutputSlot
|
||||
|| s instanceof AppEngCraftingSlot || s instanceof DisabledSlot
|
||||
|| s instanceof InaccessibleSlot || s instanceof FakeSlot
|
||||
|| s instanceof RestrictedInputSlot || s instanceof SlotDisconnected;
|
||||
if (isValid && s instanceof RestrictedInputSlot) {
|
||||
try {
|
||||
isValid = ((RestrictedInputSlot) s).isValid(is, getMinecraft().world);
|
||||
} catch (final Exception err) {
|
||||
AELog.debug(err);
|
||||
}
|
||||
}
|
||||
aeSlot.setIsValid(isValid ? CalculatedValidity.Valid : CalculatedValidity.Invalid);
|
||||
}
|
||||
|
||||
if (aeSlot.getIsValid() == CalculatedValidity.Invalid) {
|
||||
setBlitOffset(100);
|
||||
this.itemRenderer.zLevel = 100.0F;
|
||||
|
||||
fill(s.xPos, s.yPos, 16 + s.xPos, 16 + s.yPos, 0x66ff6666);
|
||||
|
||||
setBlitOffset(0);
|
||||
this.itemRenderer.zLevel = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
if (s instanceof AppEngSlot) {
|
||||
((AppEngSlot) s).setDisplay(true);
|
||||
super.drawSlot(s);
|
||||
} else {
|
||||
super.drawSlot(s);
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (final Exception err) {
|
||||
AELog.warn("[AppEng] AE prevented crash while drawing slot: " + err.toString());
|
||||
}
|
||||
}
|
||||
// do the usual for non-ME Slots.
|
||||
super.drawSlot(s);
|
||||
}
|
||||
|
||||
protected boolean isPowered() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void bindTexture(final String file) {
|
||||
final Identifier loc = new Identifier(AppEng.MOD_ID, "textures/" + file);
|
||||
getMinecraft().getTextureManager().bindTexture(loc);
|
||||
}
|
||||
|
||||
public void bindTexture(final Identifier loc) {
|
||||
getMinecraft().getTextureManager().bindTexture(loc);
|
||||
}
|
||||
|
||||
protected Scrollbar getScrollBar() {
|
||||
return this.myScrollBar;
|
||||
}
|
||||
|
||||
protected void setScrollBar(final Scrollbar myScrollBar) {
|
||||
this.myScrollBar = myScrollBar;
|
||||
}
|
||||
|
||||
protected List<InternalSlotME> getMeSlots() {
|
||||
return this.meSlots;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
|
||||
package appeng.client.gui;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
/**
|
||||
* A proxy for a slot that will always return an itemstack with size 1, if there
|
||||
* is an item in the slot. Used to prevent the default item count from
|
||||
* rendering.
|
||||
*/
|
||||
class Size1Slot extends SlotItemHandler {
|
||||
|
||||
private final SlotItemHandler delegate;
|
||||
|
||||
public Size1Slot(SlotItemHandler delegate) {
|
||||
super(delegate.getItemHandler(), delegate.getSlotIndex(), delegate.xPos, delegate.yPos);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStack() {
|
||||
ItemStack orgStack = this.delegate.getStack();
|
||||
if (!orgStack.isEmpty()) {
|
||||
ItemStack modifiedStack = orgStack.copy();
|
||||
modifiedStack.setCount(1);
|
||||
return modifiedStack;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasStack() {
|
||||
return this.delegate.getHasStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return this.delegate.getSlotStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack) {
|
||||
return this.delegate.getItemStackLimit(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(PlayerEntity playerIn) {
|
||||
return this.delegate.canTakeStack(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean isEnabled() {
|
||||
return this.delegate.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotIndex() {
|
||||
return this.delegate.getSlotIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameInventory(Slot other) {
|
||||
return this.delegate.isSameInventory(other);
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.TabButton;
|
||||
import appeng.container.implementations.ChestContainer;
|
||||
import appeng.container.implementations.CraftingTermContainer;
|
||||
import appeng.container.implementations.MEMonitorableContainer;
|
||||
import appeng.container.implementations.PatternTermContainer;
|
||||
import appeng.container.implementations.WirelessTermContainer;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.SwitchGuisPacket;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import appeng.parts.reporting.CraftingTerminalPart;
|
||||
import appeng.parts.reporting.PatternTerminalPart;
|
||||
import appeng.parts.reporting.TerminalPart;
|
||||
import appeng.tile.storage.ChestBlockEntity;
|
||||
|
||||
/**
|
||||
* Utility class for sub-screens of other containers that allow returning to the
|
||||
* primary container UI.
|
||||
*/
|
||||
final class AESubScreen {
|
||||
|
||||
private final AEBaseScreen<?> gui;
|
||||
private final ScreenHandlerType<?> previousContainerType;
|
||||
private final ItemStack previousContainerIcon;
|
||||
|
||||
/**
|
||||
* Based on the container we're opening for, try to determine what it's
|
||||
* "primary" GUI would be so that we can go back to it.
|
||||
*/
|
||||
public AESubScreen(AEBaseScreen<?> gui, Object containerTarget) {
|
||||
this.gui = gui;
|
||||
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IParts parts = definitions.parts();
|
||||
|
||||
if (containerTarget instanceof ChestBlockEntity) {
|
||||
// A chest is also a priority host, but the priority _interface_ can only be
|
||||
// opened from the
|
||||
// chest ui that doesn't actually show the contents of the inserted cell.
|
||||
IPriorityHost priorityHost = (IPriorityHost) containerTarget;
|
||||
this.previousContainerIcon = priorityHost.getItemStackRepresentation();
|
||||
this.previousContainerType = ChestContainer.TYPE;
|
||||
}
|
||||
|
||||
else if (containerTarget instanceof IPriorityHost) {
|
||||
IPriorityHost priorityHost = (IPriorityHost) containerTarget;
|
||||
this.previousContainerIcon = priorityHost.getItemStackRepresentation();
|
||||
this.previousContainerType = priorityHost.getContainerType();
|
||||
}
|
||||
|
||||
else if (containerTarget instanceof WirelessTerminalGuiObject) {
|
||||
this.previousContainerIcon = definitions.items().wirelessTerminal().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
this.previousContainerType = WirelessTermContainer.TYPE;
|
||||
}
|
||||
|
||||
else if (containerTarget instanceof TerminalPart) {
|
||||
this.previousContainerIcon = parts.terminal().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
this.previousContainerType = MEMonitorableContainer.TYPE;
|
||||
}
|
||||
|
||||
else if (containerTarget instanceof CraftingTerminalPart) {
|
||||
this.previousContainerIcon = parts.craftingTerminal().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
this.previousContainerType = CraftingTermContainer.TYPE;
|
||||
}
|
||||
|
||||
else if (containerTarget instanceof PatternTerminalPart) {
|
||||
this.previousContainerIcon = parts.patternTerminal().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
this.previousContainerType = PatternTermContainer.TYPE;
|
||||
}
|
||||
|
||||
else {
|
||||
this.previousContainerIcon = null;
|
||||
this.previousContainerType = null;
|
||||
}
|
||||
}
|
||||
|
||||
public final TabButton addBackButton(Consumer<TabButton> buttonAdder, int x, int y) {
|
||||
return addBackButton(buttonAdder, x, y, null);
|
||||
}
|
||||
|
||||
public final TabButton addBackButton(Consumer<TabButton> buttonAdder, int x, int y, @Nullable String label) {
|
||||
if (this.previousContainerType != null && !previousContainerIcon.isEmpty()) {
|
||||
if (label == null) {
|
||||
label = previousContainerIcon.getName().getString();
|
||||
}
|
||||
ItemRenderer itemRenderer = gui.getMinecraft().getItemRenderer();
|
||||
TabButton button = new TabButton(gui.getGuiLeft() + x, gui.getGuiTop() + y, previousContainerIcon, label,
|
||||
itemRenderer, btn -> goBack());
|
||||
buttonAdder.accept(button);
|
||||
return button;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final void goBack() {
|
||||
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(this.previousContainerType));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.api.config.CopyMode;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.client.gui.widgets.ActionButton;
|
||||
import appeng.client.gui.widgets.SettingToggleButton;
|
||||
import appeng.client.gui.widgets.ToggleButton;
|
||||
import appeng.container.implementations.CellWorkbenchContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
|
||||
public class CellWorkbenchScreen extends UpgradeableScreen<CellWorkbenchContainer> {
|
||||
|
||||
private ToggleButton copyMode;
|
||||
|
||||
public CellWorkbenchScreen(CellWorkbenchContainer container, PlayerInventory playerInventory,
|
||||
Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 251;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons() {
|
||||
this.fuzzyMode = this.addButton(new SettingToggleButton<>(this.guiLeft - 18, this.guiTop + 68,
|
||||
Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::toggleFuzzyMode));
|
||||
this.addButton(
|
||||
new ActionButton(this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, act1 -> action("Partition")));
|
||||
this.addButton(new ActionButton(this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, act -> action("Clear")));
|
||||
this.copyMode = this.addButton(new ToggleButton(this.guiLeft - 18, this.guiTop + 48, 11 * 16 + 5, 12 * 16 + 5,
|
||||
GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc.getLocal(), act -> action("CopyMode")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.handleButtonVisibility();
|
||||
|
||||
this.bindTexture(this.getBackground());
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, 211 - 34, this.ySize, getBlitOffset());
|
||||
if (this.drawUpgrades()) {
|
||||
if (this.container.availableUpgrades() <= 8) {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY, 177, 0, 35,
|
||||
7 + this.container.availableUpgrades() * 18, getBlitOffset());
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY + (7 + (this.container.availableUpgrades()) * 18),
|
||||
177, 151, 35, 7, getBlitOffset());
|
||||
} else if (this.container.availableUpgrades() <= 16) {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18, getBlitOffset());
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7,
|
||||
getBlitOffset());
|
||||
|
||||
final int dx = this.container.availableUpgrades() - 8;
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + dx * 18,
|
||||
getBlitOffset());
|
||||
if (dx == 8) {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8, 7,
|
||||
getBlitOffset());
|
||||
} else {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151,
|
||||
35 - 8, 7, getBlitOffset());
|
||||
}
|
||||
} else {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18, getBlitOffset());
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7,
|
||||
getBlitOffset());
|
||||
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + 8 * 18,
|
||||
getBlitOffset());
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27, offsetY + (7 + (8) * 18), 186, 151, 35 - 8, 7,
|
||||
getBlitOffset());
|
||||
|
||||
final int dx = this.container.availableUpgrades() - 16;
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27 + 18, offsetY, 186, 0, 35 - 8, 7 + dx * 18,
|
||||
getBlitOffset());
|
||||
if (dx == 8) {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27 + 18, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8,
|
||||
7, getBlitOffset());
|
||||
} else {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 177 + 27 + 18 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151,
|
||||
35 - 8, 7, getBlitOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hasToolbox()) {
|
||||
GuiUtils.drawTexturedModalRect(offsetX + 178, offsetY + this.ySize - 90, 178, 161, 68, 68, getBlitOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleButtonVisibility() {
|
||||
this.copyMode.setState(this.container.getCopyMode() == CopyMode.CLEAR_ON_REMOVE);
|
||||
|
||||
boolean hasFuzzy = false;
|
||||
final FixedItemInv inv = this.container.getCellUpgradeInventory();
|
||||
for (int x = 0; x < inv.getSlotCount(); x++) {
|
||||
final ItemStack is = inv.getInvStack(x);
|
||||
if (!is.isEmpty() && is.getItem() instanceof IUpgradeModule) {
|
||||
if (((IUpgradeModule) is.getItem()).getType(is) == Upgrades.FUZZY) {
|
||||
hasFuzzy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.fuzzyMode.setVisibility(hasFuzzy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "guis/cellworkbench.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean drawUpgrades() {
|
||||
return this.container.availableUpgrades() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName() {
|
||||
return GuiText.CellWorkbench;
|
||||
}
|
||||
|
||||
private void action(String type) {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("CellWorkbench.Action", type));
|
||||
}
|
||||
|
||||
private void toggleFuzzyMode(SettingToggleButton<FuzzyMode> button, boolean backwards) {
|
||||
FuzzyMode fz = button.getNextValue(backwards);
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("CellWorkbench.Fuzzy", fz.name()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.TabButton;
|
||||
import appeng.container.implementations.ChestContainer;
|
||||
import appeng.container.implementations.PriorityContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.SwitchGuisPacket;
|
||||
|
||||
public class ChestScreen extends AEBaseScreen<ChestContainer> {
|
||||
|
||||
public ChestScreen(ChestContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 166;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.addButton(new TabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(),
|
||||
this.itemRenderer, btn -> openPriority()));
|
||||
}
|
||||
|
||||
private void openPriority() {
|
||||
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.font.drawString(this.getGuiDisplayName(GuiText.Chest.getLocal()), 8, 6, 4210752);
|
||||
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.bindTexture("guis/chest.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.config.CondenserOutput;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.ProgressBar;
|
||||
import appeng.client.gui.widgets.ProgressBar.Direction;
|
||||
import appeng.client.gui.widgets.ServerSettingToggleButton;
|
||||
import appeng.client.gui.widgets.SettingToggleButton;
|
||||
import appeng.container.implementations.CondenserContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
||||
public class CondenserScreen extends AEBaseScreen<CondenserContainer> {
|
||||
|
||||
private SettingToggleButton<CondenserOutput> mode;
|
||||
|
||||
public CondenserScreen(CondenserContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 197;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.mode = new ServerSettingToggleButton<>(128 + this.guiLeft, 52 + this.guiTop, Settings.CONDENSER_OUTPUT,
|
||||
this.container.getOutput());
|
||||
|
||||
this.addButton(new ProgressBar(this.container, "guis/condenser.png", 120 + this.guiLeft, 25 + this.guiTop, 178,
|
||||
25, 6, 18, Direction.VERTICAL, GuiText.StoredEnergy.getLocal()));
|
||||
this.addButton(this.mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.font.drawString(this.getGuiDisplayName(GuiText.Condenser.getLocal()), 8, 6, 4210752);
|
||||
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
|
||||
|
||||
this.mode.set(this.container.getOutput());
|
||||
this.mode.setFillVar(String.valueOf(this.container.getOutput().requiredPower));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.bindTexture("guis/condenser.png");
|
||||
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.NumberBox;
|
||||
import appeng.container.implementations.CraftAmountContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.CraftRequestPacket;
|
||||
|
||||
public class CraftAmountScreen extends AEBaseScreen<CraftAmountContainer> {
|
||||
private final AESubScreen subGui;
|
||||
|
||||
private NumberBox amountToCraft;
|
||||
|
||||
private Button next;
|
||||
|
||||
public CraftAmountScreen(CraftAmountContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.subGui = new AESubScreen(this, container.getTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final int a = AEConfig.instance().craftItemsByStackAmounts(0);
|
||||
final int b = AEConfig.instance().craftItemsByStackAmounts(1);
|
||||
final int c = AEConfig.instance().craftItemsByStackAmounts(2);
|
||||
final int d = AEConfig.instance().craftItemsByStackAmounts(3);
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a, btn -> addQty(a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b, btn -> addQty(b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c, btn -> addQty(c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d, btn -> addQty(d)));
|
||||
|
||||
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a, btn -> addQty(-a)));
|
||||
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b, btn -> addQty(-b)));
|
||||
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c, btn -> addQty(-c)));
|
||||
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d, btn -> addQty(-d)));
|
||||
|
||||
this.next = this.addButton(
|
||||
new Button(this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal(), this::confirm));
|
||||
|
||||
subGui.addBackButton(this::addButton, 154, 0);
|
||||
|
||||
this.amountToCraft = new NumberBox(this.font, this.guiLeft + 62, this.guiTop + 57, 59, this.font.FONT_HEIGHT,
|
||||
Integer.class);
|
||||
this.amountToCraft.setEnableBackgroundDrawing(false);
|
||||
this.amountToCraft.setMaxStringLength(16);
|
||||
this.amountToCraft.setTextColor(0xFFFFFF);
|
||||
this.amountToCraft.setVisible(true);
|
||||
this.amountToCraft.setFocused2(true);
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
|
||||
private void confirm(Button button) {
|
||||
NetworkHandler.instance()
|
||||
.sendToServer(new CraftRequestPacket(Integer.parseInt(this.amountToCraft.getText()), hasShiftDown()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.font.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.next.setMessage(hasShiftDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal());
|
||||
|
||||
this.bindTexture("guis/craft_amt.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
|
||||
try {
|
||||
Long.parseLong(this.amountToCraft.getText());
|
||||
this.next.active = !this.amountToCraft.getText().isEmpty();
|
||||
} catch (final NumberFormatException e) {
|
||||
this.next.active = false;
|
||||
}
|
||||
|
||||
this.amountToCraft.render(offsetX, offsetY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char ch, int p_charTyped_2_) {
|
||||
// Forward entered text to the craft amount text-field
|
||||
return this.amountToCraft.charTyped(ch, p_charTyped_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
if (!this.checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode))) {
|
||||
if (keyCode == 28) {
|
||||
this.next.onPress();
|
||||
}
|
||||
if ((keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14)
|
||||
&& this.amountToCraft.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
final long result = Long.parseLong(out);
|
||||
if (result < 0) {
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
|
||||
private void addQty(final int i) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
long result = Integer.parseInt(out);
|
||||
|
||||
if (result == 1 && i > 1) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
result += i;
|
||||
if (result < 1) {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
out = Long.toString(result);
|
||||
Integer.parseInt(out);
|
||||
this.amountToCraft.setText(out);
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "guis/craftAmt.png";
|
||||
}
|
||||
}
|
||||
@@ -1,460 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.Scrollbar;
|
||||
import appeng.container.implementations.CraftConfirmContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CraftConfirmScreen extends AEBaseScreen<CraftConfirmContainer> {
|
||||
|
||||
private final AESubScreen subGui;
|
||||
|
||||
private final int rows = 5;
|
||||
|
||||
private final IItemList<IAEItemStack> storage = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
private final IItemList<IAEItemStack> pending = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
private final List<IAEItemStack> visual = new ArrayList<>();
|
||||
|
||||
private Button start;
|
||||
private Button selectCPU;
|
||||
private int tooltip = -1;
|
||||
|
||||
public CraftConfirmScreen(CraftConfirmContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.subGui = new AESubScreen(this, container.getTarget());
|
||||
this.xSize = 238;
|
||||
this.ySize = 206;
|
||||
|
||||
final Scrollbar scrollbar = new Scrollbar();
|
||||
this.setScrollBar(scrollbar);
|
||||
}
|
||||
|
||||
boolean isAutoStart() {
|
||||
return this.container.isAutoStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.start = new Button(this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal(),
|
||||
btn -> start());
|
||||
this.start.active = false;
|
||||
this.addButton(this.start);
|
||||
|
||||
this.selectCPU = new Button(this.guiLeft + (219 - 180) / 2, this.guiTop + this.ySize - 68, 180, 20,
|
||||
GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic, btn -> selectNextCpu());
|
||||
this.selectCPU.active = false;
|
||||
this.addButton(this.selectCPU);
|
||||
|
||||
addButton(new Button(this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal(),
|
||||
btn -> subGui.goBack()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final int mouseX, final int mouseY, final float btn) {
|
||||
this.updateCPUButtonText();
|
||||
|
||||
this.start.active = !(this.container.hasNoCPU() || this.isSimulation());
|
||||
this.selectCPU.active = !this.isSimulation();
|
||||
|
||||
final int gx = (this.width - this.xSize) / 2;
|
||||
final int gy = (this.height - this.ySize) / 2;
|
||||
|
||||
this.tooltip = -1;
|
||||
|
||||
final int offY = 23;
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
for (int z = 0; z <= 4 * 5; z++) {
|
||||
final int minX = gx + 9 + x * 67;
|
||||
final int minY = gy + 22 + y * offY;
|
||||
|
||||
if (minX < mouseX && minX + 67 > mouseX) {
|
||||
if (minY < mouseY && minY + offY - 2 > mouseY) {
|
||||
this.tooltip = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
super.render(mouseX, mouseY, btn);
|
||||
}
|
||||
|
||||
private void updateCPUButtonText() {
|
||||
String btnTextText = GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic.getLocal();
|
||||
if (this.container.getSelectedCpu() >= 0)// && status.selectedCpu < status.cpus.size() )
|
||||
{
|
||||
if (this.container.getName() != null) {
|
||||
final String name = this.container.getName().getStringTruncated(20);
|
||||
btnTextText = GuiText.CraftingCPU.getLocal() + ": " + name;
|
||||
} else {
|
||||
btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + this.container.getSelectedCpu();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.container.hasNoCPU()) {
|
||||
btnTextText = GuiText.NoCraftingCPUs.getLocal();
|
||||
}
|
||||
|
||||
this.selectCPU.setMessage(btnTextText);
|
||||
}
|
||||
|
||||
private boolean isSimulation() {
|
||||
return this.container.isSimulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
final long BytesUsed = this.container.getUsedBytes();
|
||||
final String byteUsed = NumberFormat.getInstance().format(BytesUsed);
|
||||
final String Add = BytesUsed > 0 ? (byteUsed + ' ' + GuiText.BytesUsed.getLocal())
|
||||
: GuiText.CalculatingWait.getLocal();
|
||||
this.font.drawString(GuiText.CraftingPlan.getLocal() + " - " + Add, 8, 7, 4210752);
|
||||
|
||||
String dsp = null;
|
||||
|
||||
if (this.isSimulation()) {
|
||||
dsp = GuiText.Simulation.getLocal();
|
||||
} else {
|
||||
dsp = this.container.getCpuAvailableBytes() > 0
|
||||
? (GuiText.Bytes.getLocal() + ": " + this.container.getCpuAvailableBytes() + " : "
|
||||
+ GuiText.CoProcessors.getLocal() + ": " + this.container.getCpuCoProcessors())
|
||||
: GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A";
|
||||
}
|
||||
|
||||
final int offset = (219 - this.font.getStringWidth(dsp)) / 2;
|
||||
this.font.drawString(dsp, offset, 165, 4210752);
|
||||
|
||||
final int sectionLength = 67;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
final int xo = 9;
|
||||
final int yo = 22;
|
||||
final int viewStart = this.getScrollBar().getCurrentScroll() * 3;
|
||||
final int viewEnd = viewStart + 3 * this.rows;
|
||||
|
||||
String dspToolTip = "";
|
||||
final List<String> lineList = new ArrayList<>();
|
||||
int toolPosX = 0;
|
||||
int toolPosY = 0;
|
||||
|
||||
final int offY = 23;
|
||||
|
||||
for (int z = viewStart; z < Math.min(viewEnd, this.visual.size()); z++) {
|
||||
final IAEItemStack refStack = this.visual.get(z);// repo.getReferenceItem( z );
|
||||
if (refStack != null) {
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(0.5f, 0.5f, 0.5f);
|
||||
|
||||
final IAEItemStack stored = this.storage.findPrecise(refStack);
|
||||
final IAEItemStack pendingStack = this.pending.findPrecise(refStack);
|
||||
final IAEItemStack missingStack = this.missing.findPrecise(refStack);
|
||||
|
||||
int lines = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
if (missingStack != null && missingStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
|
||||
final int negY = ((lines - 1) * 5) / 2;
|
||||
int downY = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
String str = Long.toString(stored.getStackSize());
|
||||
if (stored.getStackSize() >= 10000) {
|
||||
str = Long.toString(stored.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (stored.getStackSize() >= 10000000) {
|
||||
str = Long.toString(stored.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.FromStorage.getLocal() + ": " + str;
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2, 4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.FromStorage.getLocal() + ": " + Long.toString(stored.getStackSize()));
|
||||
}
|
||||
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
boolean red = false;
|
||||
if (missingStack != null && missingStack.getStackSize() > 0) {
|
||||
String str = Long.toString(missingStack.getStackSize());
|
||||
if (missingStack.getStackSize() >= 10000) {
|
||||
str = Long.toString(missingStack.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (missingStack.getStackSize() >= 10000000) {
|
||||
str = Long.toString(missingStack.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.Missing.getLocal() + ": " + str;
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2, 4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.Missing.getLocal() + ": " + Long.toString(missingStack.getStackSize()));
|
||||
}
|
||||
|
||||
red = true;
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
String str = Long.toString(pendingStack.getStackSize());
|
||||
if (pendingStack.getStackSize() >= 10000) {
|
||||
str = Long.toString(pendingStack.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (pendingStack.getStackSize() >= 10000000) {
|
||||
str = Long.toString(pendingStack.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.ToCraft.getLocal() + ": " + str;
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2, 4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.ToCraft.getLocal() + ": " + Long.toString(pendingStack.getStackSize()));
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem.popMatrix();
|
||||
final int posX = x * (1 + sectionLength) + xo + sectionLength - 19;
|
||||
final int posY = y * offY + yo;
|
||||
|
||||
final ItemStack is = refStack.asItemStackRepresentation();
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
dspToolTip = Platform.getItemDisplayName(refStack).getFormattedText();
|
||||
|
||||
if (lineList.size() > 0) {
|
||||
dspToolTip = dspToolTip + '\n' + Joiner.on("\n").join(lineList);
|
||||
}
|
||||
|
||||
toolPosX = x * (1 + sectionLength) + xo + sectionLength - 8;
|
||||
toolPosY = y * offY + yo;
|
||||
}
|
||||
|
||||
this.drawItem(posX, posY, is);
|
||||
|
||||
if (red) {
|
||||
final int startX = x * (1 + sectionLength) + xo;
|
||||
final int startY = posY - 4;
|
||||
fill(startX, startY, startX + sectionLength, startY + offY, 0x1AFF0000);
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.tooltip >= 0 && !dspToolTip.isEmpty()) {
|
||||
this.drawTooltip(toolPosX, toolPosY + 10, dspToolTip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.setScrollBar();
|
||||
this.bindTexture("guis/craftingreport.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
}
|
||||
|
||||
private void setScrollBar() {
|
||||
final int size = this.visual.size();
|
||||
|
||||
this.getScrollBar().setTop(19).setLeft(218).setHeight(114);
|
||||
this.getScrollBar().setRange(0, (size + 2) / 3 - this.rows, 1);
|
||||
}
|
||||
|
||||
public void postUpdate(final List<IAEItemStack> list, final byte ref) {
|
||||
switch (ref) {
|
||||
case 0:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.storage, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.pending, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.missing, l);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (final IAEItemStack l : list) {
|
||||
final long amt = this.getTotal(l);
|
||||
|
||||
if (amt <= 0) {
|
||||
this.deleteVisualStack(l);
|
||||
} else {
|
||||
final IAEItemStack is = this.findVisualStack(l);
|
||||
is.setStackSize(amt);
|
||||
}
|
||||
}
|
||||
|
||||
this.setScrollBar();
|
||||
}
|
||||
|
||||
private void handleInput(final IItemList<IAEItemStack> s, final IAEItemStack l) {
|
||||
IAEItemStack a = s.findPrecise(l);
|
||||
|
||||
if (l.getStackSize() <= 0) {
|
||||
if (a != null) {
|
||||
a.reset();
|
||||
}
|
||||
} else {
|
||||
if (a == null) {
|
||||
s.add(l.copy());
|
||||
a = s.findPrecise(l);
|
||||
}
|
||||
|
||||
if (a != null) {
|
||||
a.setStackSize(l.getStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getTotal(final IAEItemStack is) {
|
||||
final IAEItemStack a = this.storage.findPrecise(is);
|
||||
final IAEItemStack c = this.pending.findPrecise(is);
|
||||
final IAEItemStack m = this.missing.findPrecise(is);
|
||||
|
||||
long total = 0;
|
||||
|
||||
if (a != null) {
|
||||
total += a.getStackSize();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
total += c.getStackSize();
|
||||
}
|
||||
|
||||
if (m != null) {
|
||||
total += m.getStackSize();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private void deleteVisualStack(final IAEItemStack l) {
|
||||
final Iterator<IAEItemStack> i = this.visual.iterator();
|
||||
while (i.hasNext()) {
|
||||
final IAEItemStack o = i.next();
|
||||
if (o.equals(l)) {
|
||||
i.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IAEItemStack findVisualStack(final IAEItemStack l) {
|
||||
for (final IAEItemStack o : this.visual) {
|
||||
if (o.equals(l)) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
final IAEItemStack stack = l.copy();
|
||||
this.visual.add(stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
if (!this.checkHotbarKeys(InputMappings.getInputByCode(keyCode, scanCode))) {
|
||||
if (keyCode == 28) {
|
||||
this.start();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
|
||||
private void selectNextCpu() {
|
||||
final boolean backwards = minecraft.mouseHelper.isRightDown();
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("Terminal.Cpu", backwards ? "Prev" : "Next"));
|
||||
}
|
||||
|
||||
private void start() {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("Terminal.Start", "Start"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,429 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.ISortSource;
|
||||
import appeng.client.gui.widgets.Scrollbar;
|
||||
import appeng.container.implementations.CraftingCPUContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
|
||||
public class CraftingCPUScreen<T extends CraftingCPUContainer> extends AEBaseScreen<T> implements ISortSource {
|
||||
private static final int GUI_HEIGHT = 184;
|
||||
private static final int GUI_WIDTH = 238;
|
||||
|
||||
private static final int DISPLAYED_ROWS = 6;
|
||||
|
||||
private static final int TEXT_COLOR = 0x404040;
|
||||
private static final int BACKGROUND_ALPHA = 0x5A000000;
|
||||
|
||||
private static final int SECTION_LENGTH = 67;
|
||||
|
||||
private static final int SCROLLBAR_TOP = 19;
|
||||
private static final int SCROLLBAR_LEFT = 218;
|
||||
private static final int SCROLLBAR_HEIGHT = 137;
|
||||
|
||||
private static final int CANCEL_LEFT_OFFSET = 163;
|
||||
private static final int CANCEL_TOP_OFFSET = 25;
|
||||
private static final int CANCEL_HEIGHT = 20;
|
||||
private static final int CANCEL_WIDTH = 50;
|
||||
|
||||
private static final int TITLE_TOP_OFFSET = 7;
|
||||
private static final int TITLE_LEFT_OFFSET = 8;
|
||||
|
||||
private static final int ITEMSTACK_LEFT_OFFSET = 9;
|
||||
private static final int ITEMSTACK_TOP_OFFSET = 22;
|
||||
|
||||
private IItemList<IAEItemStack> storage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createList();
|
||||
private IItemList<IAEItemStack> active = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createList();
|
||||
private IItemList<IAEItemStack> pending = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createList();
|
||||
|
||||
private List<IAEItemStack> visual = new ArrayList<>();
|
||||
private Button cancel;
|
||||
private int tooltip = -1;
|
||||
|
||||
public CraftingCPUScreen(T container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = GUI_HEIGHT;
|
||||
this.xSize = GUI_WIDTH;
|
||||
|
||||
final Scrollbar scrollbar = new Scrollbar();
|
||||
this.setScrollBar(scrollbar);
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
this.storage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
this.active = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
this.pending = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
this.visual = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("TileCrafting.Cancel", "Cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
this.setScrollBar();
|
||||
this.cancel = new Button(this.guiLeft + CANCEL_LEFT_OFFSET, this.guiTop + this.ySize - CANCEL_TOP_OFFSET,
|
||||
CANCEL_WIDTH, CANCEL_HEIGHT, GuiText.Cancel.getLocal(), btn -> cancel());
|
||||
this.addButton(this.cancel);
|
||||
}
|
||||
|
||||
private void setScrollBar() {
|
||||
final int size = this.visual.size();
|
||||
|
||||
this.getScrollBar().setTop(SCROLLBAR_TOP).setLeft(SCROLLBAR_LEFT).setHeight(SCROLLBAR_HEIGHT);
|
||||
this.getScrollBar().setRange(0, (size + 2) / 3 - DISPLAYED_ROWS, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final int mouseX, final int mouseY, final float btn) {
|
||||
this.cancel.active = !this.visual.isEmpty();
|
||||
|
||||
final int gx = (this.width - this.xSize) / 2;
|
||||
final int gy = (this.height - this.ySize) / 2;
|
||||
|
||||
this.tooltip = -1;
|
||||
|
||||
final int offY = 23;
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
for (int z = 0; z <= 4 * 5; z++) {
|
||||
final int minX = gx + 9 + x * 67;
|
||||
final int minY = gy + 22 + y * offY;
|
||||
|
||||
if (minX < mouseX && minX + 67 > mouseX) {
|
||||
if (minY < mouseY && minY + offY - 2 > mouseY) {
|
||||
this.tooltip = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
super.render(mouseX, mouseY, btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
String title = this.getGuiDisplayName(GuiText.CraftingStatus.getLocal());
|
||||
|
||||
if (this.container.getEstimatedTime() > 0 && !this.visual.isEmpty()) {
|
||||
final long etaInMilliseconds = TimeUnit.MILLISECONDS.convert(this.container.getEstimatedTime(),
|
||||
TimeUnit.NANOSECONDS);
|
||||
final String etaTimeText = DurationFormatUtils.formatDuration(etaInMilliseconds,
|
||||
GuiText.ETAFormat.getLocal());
|
||||
title += " - " + etaTimeText;
|
||||
}
|
||||
|
||||
this.font.drawString(title, TITLE_LEFT_OFFSET, TITLE_TOP_OFFSET, TEXT_COLOR);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
final int viewStart = this.getScrollBar().getCurrentScroll() * 3;
|
||||
final int viewEnd = viewStart + 3 * 6;
|
||||
|
||||
String dspToolTip = "";
|
||||
final List<String> lineList = new ArrayList<>();
|
||||
int toolPosX = 0;
|
||||
int toolPosY = 0;
|
||||
|
||||
final int offY = 23;
|
||||
|
||||
final ReadableNumberConverter converter = ReadableNumberConverter.INSTANCE;
|
||||
for (int z = viewStart; z < Math.min(viewEnd, this.visual.size()); z++) {
|
||||
final IAEItemStack refStack = this.visual.get(z);// repo.getReferenceItem( z );
|
||||
if (refStack != null) {
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(0.5f, 0.5f, 0.5f);
|
||||
|
||||
final IAEItemStack stored = this.storage.findPrecise(refStack);
|
||||
final IAEItemStack activeStack = this.active.findPrecise(refStack);
|
||||
final IAEItemStack pendingStack = this.pending.findPrecise(refStack);
|
||||
|
||||
int lines = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
boolean active = false;
|
||||
if (activeStack != null && activeStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
active = true;
|
||||
}
|
||||
boolean scheduled = false;
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
scheduled = true;
|
||||
}
|
||||
|
||||
if (AEConfig.instance().isUseColoredCraftingStatus() && (active || scheduled)) {
|
||||
final int bgColor = (active ? AEColor.GREEN.blackVariant : AEColor.YELLOW.blackVariant)
|
||||
| BACKGROUND_ALPHA;
|
||||
final int startX = (x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET) * 2;
|
||||
final int startY = ((y * offY + ITEMSTACK_TOP_OFFSET) - 3) * 2;
|
||||
fill(startX, startY, startX + (SECTION_LENGTH * 2), startY + (offY * 2) - 2, bgColor);
|
||||
}
|
||||
|
||||
final int negY = ((lines - 1) * 5) / 2;
|
||||
int downY = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
final String str = GuiText.Stored.getLocal() + ": "
|
||||
+ converter.toWideReadableForm(stored.getStackSize());
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19 - (w * 0.5))
|
||||
* 2),
|
||||
(y * offY + ITEMSTACK_TOP_OFFSET + 6 - negY + downY) * 2, TEXT_COLOR);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.Stored.getLocal() + ": " + Long.toString(stored.getStackSize()));
|
||||
}
|
||||
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
if (activeStack != null && activeStack.getStackSize() > 0) {
|
||||
final String str = GuiText.Crafting.getLocal() + ": "
|
||||
+ converter.toWideReadableForm(activeStack.getStackSize());
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19 - (w * 0.5))
|
||||
* 2),
|
||||
(y * offY + ITEMSTACK_TOP_OFFSET + 6 - negY + downY) * 2, TEXT_COLOR);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.Crafting.getLocal() + ": " + Long.toString(activeStack.getStackSize()));
|
||||
}
|
||||
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
final String str = GuiText.Scheduled.getLocal() + ": "
|
||||
+ converter.toWideReadableForm(pendingStack.getStackSize());
|
||||
final int w = 4 + this.font.getStringWidth(str);
|
||||
|
||||
this.font.drawString(str,
|
||||
(int) ((x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19 - (w * 0.5))
|
||||
* 2),
|
||||
(y * offY + ITEMSTACK_TOP_OFFSET + 6 - negY + downY) * 2, TEXT_COLOR);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.Scheduled.getLocal() + ": " + Long.toString(pendingStack.getStackSize()));
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem.popMatrix();
|
||||
final int posX = x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19;
|
||||
final int posY = y * offY + ITEMSTACK_TOP_OFFSET;
|
||||
|
||||
final ItemStack is = refStack.asItemStackRepresentation();
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
dspToolTip = Platform.getItemDisplayName(refStack).getFormattedText();
|
||||
|
||||
if (lineList.size() > 0) {
|
||||
dspToolTip = dspToolTip + '\n' + Joiner.on("\n").join(lineList);
|
||||
}
|
||||
|
||||
toolPosX = x * (1 + SECTION_LENGTH) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 8;
|
||||
toolPosY = y * offY + ITEMSTACK_TOP_OFFSET;
|
||||
}
|
||||
|
||||
this.drawItem(posX, posY, is);
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.tooltip >= 0 && !dspToolTip.isEmpty()) {
|
||||
this.drawTooltip(toolPosX, toolPosY + 10, dspToolTip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.bindTexture("guis/craftingcpu.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
}
|
||||
|
||||
public void postUpdate(final List<IAEItemStack> list, final byte ref) {
|
||||
switch (ref) {
|
||||
case 0:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.storage, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.active, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.pending, l);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (final IAEItemStack l : list) {
|
||||
final long amt = this.getTotal(l);
|
||||
|
||||
if (amt <= 0) {
|
||||
this.deleteVisualStack(l);
|
||||
} else {
|
||||
final IAEItemStack is = this.findVisualStack(l);
|
||||
is.setStackSize(amt);
|
||||
}
|
||||
}
|
||||
|
||||
this.setScrollBar();
|
||||
}
|
||||
|
||||
private void handleInput(final IItemList<IAEItemStack> s, final IAEItemStack l) {
|
||||
IAEItemStack a = s.findPrecise(l);
|
||||
|
||||
if (l.getStackSize() <= 0) {
|
||||
if (a != null) {
|
||||
a.reset();
|
||||
}
|
||||
} else {
|
||||
if (a == null) {
|
||||
s.add(l.copy());
|
||||
a = s.findPrecise(l);
|
||||
}
|
||||
|
||||
if (a != null) {
|
||||
a.setStackSize(l.getStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getTotal(final IAEItemStack is) {
|
||||
final IAEItemStack a = this.storage.findPrecise(is);
|
||||
final IAEItemStack b = this.active.findPrecise(is);
|
||||
final IAEItemStack c = this.pending.findPrecise(is);
|
||||
|
||||
long total = 0;
|
||||
|
||||
if (a != null) {
|
||||
total += a.getStackSize();
|
||||
}
|
||||
|
||||
if (b != null) {
|
||||
total += b.getStackSize();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
total += c.getStackSize();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private void deleteVisualStack(final IAEItemStack l) {
|
||||
final Iterator<IAEItemStack> i = this.visual.iterator();
|
||||
|
||||
while (i.hasNext()) {
|
||||
final IAEItemStack o = i.next();
|
||||
if (o.equals(l)) {
|
||||
i.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IAEItemStack findVisualStack(final IAEItemStack l) {
|
||||
for (final IAEItemStack o : this.visual) {
|
||||
if (o.equals(l)) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
final IAEItemStack stack = l.copy();
|
||||
this.visual.add(stack);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortOrder getSortBy() {
|
||||
return SortOrder.NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortDir getSortDir() {
|
||||
return SortDir.ASCENDING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewItems getSortDisplay() {
|
||||
return ViewItems.ALL;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import appeng.container.implementations.CraftingStatusContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
|
||||
public class CraftingStatusScreen extends CraftingCPUScreen<CraftingStatusContainer> {
|
||||
|
||||
private final AESubScreen subGui;
|
||||
|
||||
private Button selectCPU;
|
||||
|
||||
public CraftingStatusScreen(CraftingStatusContainer container, PlayerInventory playerInventory,
|
||||
Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.subGui = new AESubScreen(this, container.getTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.selectCPU = new Button(this.guiLeft + 8, this.guiTop + this.ySize - 25, 150, 20,
|
||||
GuiText.CraftingCPU.getLocal() + ": " + GuiText.NoCraftingCPUs, btn -> selectNextCpu());
|
||||
this.addButton(this.selectCPU);
|
||||
|
||||
subGui.addBackButton(btn -> {
|
||||
addButton(btn);
|
||||
btn.setHideEdge(13);
|
||||
}, 213, -4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final int mouseX, final int mouseY, final float btn) {
|
||||
this.updateCPUButtonText();
|
||||
super.render(mouseX, mouseY, btn);
|
||||
}
|
||||
|
||||
private void updateCPUButtonText() {
|
||||
String btnTextText = GuiText.NoCraftingJobs.getLocal();
|
||||
|
||||
if (this.container.selectedCpu >= 0)// && status.selectedCpu < status.cpus.size() )
|
||||
{
|
||||
if (this.container.myName != null) {
|
||||
final String name = this.container.myName.getStringTruncated(20);
|
||||
btnTextText = GuiText.CPUs.getLocal() + ": " + name;
|
||||
} else {
|
||||
btnTextText = GuiText.CPUs.getLocal() + ": #" + this.container.selectedCpu;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.container.noCPU) {
|
||||
btnTextText = GuiText.NoCraftingJobs.getLocal();
|
||||
}
|
||||
|
||||
this.selectCPU.setMessage(btnTextText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGuiDisplayName(final String in) {
|
||||
return in; // the cup name is on the button
|
||||
}
|
||||
|
||||
// FIXME: Extract to separate class? Shared with GuiCraftConfirm
|
||||
private void selectNextCpu() {
|
||||
final boolean backwards = minecraft.mouseHelper.isRightDown();
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("Terminal.Cpu", backwards ? "Prev" : "Next"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.client.gui.widgets.ActionButton;
|
||||
import appeng.container.implementations.CraftingTermContainer;
|
||||
import appeng.container.slot.CraftingMatrixSlot;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.InventoryActionPacket;
|
||||
import appeng.helpers.InventoryAction;
|
||||
|
||||
public class CraftingTermScreen extends MEMonitorableScreen<CraftingTermContainer> {
|
||||
|
||||
public CraftingTermScreen(CraftingTermContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.setReservedSpace(73);
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
Slot s = null;
|
||||
for (final Object j : this.container.inventorySlots) {
|
||||
if (j instanceof CraftingMatrixSlot) {
|
||||
s = (Slot) j;
|
||||
}
|
||||
}
|
||||
|
||||
if (s != null) {
|
||||
final InventoryActionPacket p = new InventoryActionPacket(InventoryAction.MOVE_REGION, s.slotNumber, 0);
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
ActionButton clearBtn = this.addButton(
|
||||
new ActionButton(this.guiLeft + 92, this.guiTop + this.ySize - 156, ActionItems.STASH, btn -> clear()));
|
||||
clearBtn.setHalfSize(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
super.drawFG(offsetX, offsetY, mouseX, mouseY);
|
||||
this.font.drawString(GuiText.CraftingTerminal.getLocal(), 8, this.ySize - 96 + 1 - this.getReservedSpace(),
|
||||
4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "guis/crafting.png";
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.widgets.TabButton;
|
||||
import appeng.container.implementations.DriveContainer;
|
||||
import appeng.container.implementations.PriorityContainer;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.SwitchGuisPacket;
|
||||
|
||||
public class DriveScreen extends AEBaseScreen<DriveContainer> {
|
||||
|
||||
public DriveScreen(DriveContainer container, PlayerInventory playerInventory, Text title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 199;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.addButton(new TabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(),
|
||||
this.itemRenderer, btn -> openPriorityGui()));
|
||||
}
|
||||
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.font.drawString(this.getGuiDisplayName(GuiText.Drive.getLocal()), 8, 6, 4210752);
|
||||
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
|
||||
this.bindTexture("guis/drive.png");
|
||||
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, getBlitOffset());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user