Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -1,197 +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.tile.spatial;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.YesNo;
import appeng.api.implementations.TransitionResult;
import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkEvent;
import appeng.api.networking.events.MENetworkSpatialEvent;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.hooks.TickHandler;
import appeng.me.cache.SpatialPylonCache;
import appeng.tile.grid.AENetworkInvBlockEntity;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.IWorldCallable;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements IWorldCallable<Void> {
private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 2);
private final FixedItemInv invExt = new WrapperFilteredItemHandler(this.inv, new SpatialIOFilter());
private YesNo lastRedstoneState = YesNo.UNDECIDED;
public SpatialIOPortBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
}
@Override
public CompoundTag toTag(final CompoundTag data) {
super.toTag(data);
data.putInt("lastRedstoneState", this.lastRedstoneState.ordinal());
return data;
}
@Override
public void fromTag(BlockState state, final CompoundTag data) {
super.fromTag(state, data);
if (data.contains("lastRedstoneState")) {
this.lastRedstoneState = YesNo.values()[data.getInt("lastRedstoneState")];
}
}
public boolean getRedstoneState() {
if (this.lastRedstoneState == YesNo.UNDECIDED) {
this.updateRedstoneState();
}
return this.lastRedstoneState == YesNo.YES;
}
public void updateRedstoneState() {
final YesNo currentState = this.world.getReceivedRedstonePower(this.pos) != 0 ? YesNo.YES : YesNo.NO;
if (this.lastRedstoneState != currentState) {
this.lastRedstoneState = currentState;
if (this.lastRedstoneState == YesNo.YES) {
this.triggerTransition();
}
}
}
private void triggerTransition() {
if (Platform.isServer()) {
final ItemStack cell = this.inv.getInvStack(0);
if (this.isSpatialCell(cell)) {
TickHandler.INSTANCE.addCallable(null, this);// this needs to be cross world synced.
}
}
}
private boolean isSpatialCell(final ItemStack cell) {
if (!cell.isEmpty() && cell.getItem() instanceof ISpatialStorageCell) {
final ISpatialStorageCell sc = (ISpatialStorageCell) cell.getItem();
return sc != null && sc.isSpatialStorage(cell);
}
return false;
}
@Override
public Void call(final World world) throws Exception {
if (!(world instanceof ServerWorld)) {
return null;
}
ServerWorld serverWorld = (ServerWorld) world;
final ItemStack cell = this.inv.getInvStack(0);
if (this.isSpatialCell(cell) && this.inv.getInvStack(1).isEmpty()) {
final IGrid gi = this.getProxy().getGrid();
final IEnergyGrid energy = this.getProxy().getEnergy();
final ISpatialStorageCell sc = (ISpatialStorageCell) cell.getItem();
final SpatialPylonCache spc = gi.getCache(ISpatialCache.class);
if (spc.hasRegion() && spc.isValidRegion()) {
final double req = spc.requiredPower();
final double pr = energy.extractAEPower(req, Actionable.SIMULATE, PowerMultiplier.CONFIG);
if (Math.abs(pr - req) < req * 0.001) {
final MENetworkEvent res = gi.postEvent(new MENetworkSpatialEvent(this, req));
if (!res.isCanceled()) {
int playerId = -1;
if (this.getProxy().getSecurity().isAvailable()) {
playerId = this.getProxy().getSecurity().getOwner();
}
final TransitionResult tr = sc.doSpatialTransition(cell, serverWorld, spc.getMin(), spc.getMax(),
playerId);
if (tr.success) {
energy.extractAEPower(req, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.inv.setInvStack(0, ItemStack.EMPTY);
this.inv.setInvStack(1, cell);
}
}
}
}
}
return null;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
protected @Nonnull
FixedItemInv getItemHandlerForSide(@Nonnull Direction side) {
return this.invExt;
}
@Override
public FixedItemInv getInternalInventory() {
return this.inv;
}
@Override
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
final ItemStack removed, final ItemStack added) {
}
private class SpatialIOFilter implements IAEItemFilter {
@Override
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
return slot == 1;
}
@Override
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
return (slot == 0 && SpatialIOPortBlockEntity.this.isSpatialCell(stack));
}
}
}
@@ -1,229 +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.tile.spatial;
import java.io.IOException;
import java.util.EnumSet;
import javax.annotation.Nonnull;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Direction;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.client.model.data.ModelProperty;
import appeng.api.networking.GridFlags;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.me.GridAccessException;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.implementations.SpatialPylonCalculator;
import appeng.me.cluster.implementations.SpatialPylonCluster;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.AENetworkProxyMultiblock;
import appeng.tile.grid.AENetworkBlockEntity;
public class SpatialPylonBlockEntity extends AENetworkBlockEntity implements IAEMultiBlock {
public static final ModelProperty<Integer> STATE = new ModelProperty<>(value -> {
// The lower 6 bits are used
return (value & ~0x3F) == 0;
});
public static final int DISPLAY_END_MIN = 0x01;
public static final int DISPLAY_END_MAX = 0x02;
public static final int DISPLAY_MIDDLE = 0x01 + 0x02;
public static final int DISPLAY_X = 0x04;
public static final int DISPLAY_Y = 0x08;
public static final int DISPLAY_Z = 0x04 + 0x08;
public static final int MB_STATUS = 0x01 + 0x02 + 0x04 + 0x08;
public static final int DISPLAY_ENABLED = 0x10;
public static final int DISPLAY_POWERED_ENABLED = 0x20;
public static final int NET_STATUS = 0x10 + 0x20;
private final SpatialPylonCalculator calc = new SpatialPylonCalculator(this);
private int displayBits = 0;
private SpatialPylonCluster cluster;
private boolean didHaveLight = false;
public SpatialPylonBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK);
this.getProxy().setIdlePowerUsage(0.5);
this.getProxy().setValidSides(EnumSet.noneOf(Direction.class));
}
@Override
protected AENetworkProxy createProxy() {
return new AENetworkProxyMultiblock(this, "proxy", this.getItemFromTile(this), true);
}
@Override
public void onChunkUnloaded() {
this.disconnect(false);
super.onChunkUnloaded();
}
@Override
public void onReady() {
super.onReady();
this.neighborUpdate();
}
@Override
public void remove() {
this.disconnect(false);
super.remove();
}
public void neighborUpdate() {
this.calc.calculateMultiblock(this.world, this.getLocation());
}
@Override
public void disconnect(final boolean b) {
if (this.cluster != null) {
this.cluster.destroy();
this.updateStatus(null);
}
}
@Override
public SpatialPylonCluster getCluster() {
return this.cluster;
}
@Override
public boolean isValid() {
return true;
}
public void updateStatus(final SpatialPylonCluster c) {
this.cluster = c;
this.getProxy().setValidSides(c == null ? EnumSet.noneOf(Direction.class) : EnumSet.allOf(Direction.class));
this.recalculateDisplay();
}
public void recalculateDisplay() {
final int oldBits = this.displayBits;
this.displayBits = 0;
if (this.cluster != null) {
if (this.cluster.getMin().equals(this.getLocation())) {
this.displayBits = DISPLAY_END_MIN;
} else if (this.cluster.getMax().equals(this.getLocation())) {
this.displayBits = DISPLAY_END_MAX;
} else {
this.displayBits = DISPLAY_MIDDLE;
}
switch (this.cluster.getCurrentAxis()) {
case X:
this.displayBits |= DISPLAY_X;
break;
case Y:
this.displayBits |= DISPLAY_Y;
break;
case Z:
this.displayBits |= DISPLAY_Z;
break;
default:
this.displayBits = 0;
break;
}
try {
if (this.getProxy().getEnergy().isNetworkPowered()) {
this.displayBits |= DISPLAY_POWERED_ENABLED;
}
if (this.cluster.isValid() && this.getProxy().isActive()) {
this.displayBits |= DISPLAY_ENABLED;
}
} catch (final GridAccessException e) {
// nothing?
}
}
if (oldBits != this.displayBits) {
this.markForUpdate();
}
}
@Override
public void markForUpdate() {
super.markForUpdate();
final boolean hasLight = this.getLightValue() > 0;
if (hasLight != this.didHaveLight) {
this.didHaveLight = hasLight;
this.world.getLightingProvider().checkBlock(this.pos);
}
}
@Override
public boolean canBeRotated() {
return false;
}
public int getLightValue() {
if ((this.displayBits & DISPLAY_POWERED_ENABLED) == DISPLAY_POWERED_ENABLED) {
return 8;
}
return 0;
}
@Override
protected boolean readFromStream(final PacketByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
final int old = this.displayBits;
this.displayBits = data.readByte();
return old != this.displayBits || c;
}
@Override
protected void writeToStream(final PacketByteBuf data) throws IOException {
super.writeToStream(data);
data.writeByte(this.displayBits);
}
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.recalculateDisplay();
}
@MENetworkEventSubscribe
public void activeRender(final MENetworkChannelsChanged c) {
this.recalculateDisplay();
}
public int getDisplayBits() {
return this.displayBits;
}
@Override
public Object getRenderAttachmentData() {
return getDisplayBits();
}
}