Working in part placement

This commit is contained in:
Sebastian Hartte
2020-07-01 21:27:37 +02:00
parent 8e031ca8d6
commit f2e3d81fd7
134 changed files with 1553 additions and 1494 deletions
@@ -261,7 +261,7 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult
for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) {
final WorldCoord wc = new WorldCoord(te);
wc.add(d, 1);
if (this.world.isAirBlock(wc.getPos())) {
if (this.world.isAir(wc.getPos())) {
places.add(wc);
}
}
@@ -25,6 +25,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.texture.SpriteAtlasTexture;
@@ -37,7 +38,6 @@ import net.minecraft.client.renderer.RenderState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
@@ -116,7 +116,7 @@ public class MolecularAssemblerRenderer extends BlockEntityRenderer<MolecularAss
if (status.getTicksUntilParticles() <= 0) {
status.setTicksUntilParticles(4);
if (AppEng.proxy.shouldAddParticles(particleRandom)) {
if (AppEng.instance().shouldAddParticles(particleRandom)) {
for (int x = 0; x < (int) Math.ceil(status.getSpeed() / 5.0); x++) {
minecraft.particleManager.addParticle(ParticleTypes.CRAFTING, centerX, centerY, centerZ, 0, 0, 0);
}
@@ -156,7 +156,7 @@ public class MolecularAssemblerRenderer extends BlockEntityRenderer<MolecularAss
.transparency(TRANSLUCENT_TRANSPARENCY).alpha(new RenderState.AlphaState(0.05F))
.lightmap(disableLightmap).build(true);
return RenderLayer.makeType("ae2_translucent_alphatest", DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP,
return RenderLayer.makeType("ae2_translucent_alphatest", VertexFormats.POSITION_COLOR_TEX_LIGHTMAP,
GL11.GL_QUADS, 256, glState);
}
@@ -79,14 +79,14 @@ public class AENetworkBlockEntity extends AEBaseBlockEntity implements IActionHo
}
@Override
public void remove() {
super.remove();
public void markRemoved() {
super.markRemoved();
this.getProxy().remove();
}
@Override
public void validate() {
super.validate();
public void cancelRemoval() {
super.cancelRemoval();
this.getProxy().validate();
}
@@ -78,14 +78,14 @@ public abstract class AENetworkInvBlockEntity extends AEBaseInvBlockEntity imple
}
@Override
public void remove() {
super.remove();
public void markRemoved() {
super.markRemoved();
this.getProxy().remove();
}
@Override
public void validate() {
super.validate();
public void cancelRemoval() {
super.cancelRemoval();
this.getProxy().validate();
}
@@ -78,14 +78,14 @@ public abstract class AENetworkPowerBlockEntity extends AEBasePoweredBlockEntity
}
@Override
public void validate() {
super.validate();
public void cancelRemoval() {
super.cancelRemoval();
this.getProxy().validate();
}
@Override
public void remove() {
super.remove();
public void markRemoved() {
super.markRemoved();
this.getProxy().remove();
}
@@ -1,335 +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.tile.networking;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import appeng.api.networking.IGridNode;
import appeng.api.parts.IFacadeContainer;
import appeng.api.parts.IPart;
import appeng.api.parts.LayerFlags;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.client.render.cablebus.CableBusRenderState;
import appeng.helpers.AEMultiTile;
import appeng.hooks.TickHandler;
import appeng.parts.CableBusContainer;
import appeng.tile.AEBaseBlockEntity;
import appeng.util.Platform;
public class CableBusBlockEntity extends AEBaseBlockEntity implements AEMultiTile {
private CableBusContainer cb = new CableBusContainer(this);
private int oldLV = -1; // on re-calculate light when it changes
public CableBusBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@Override
public void fromTag(BlockState state, final CompoundTag data) {
super.fromTag(state, data);
this.getCableBus().readFromNBT(data);
}
@Override
public CompoundTag toTag(final CompoundTag data) {
super.toTag(data);
this.getCableBus().writeToNBT(data);
return data;
}
@Override
protected boolean readFromStream(final PacketByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
boolean ret = this.getCableBus().readFromStream(data);
final int newLV = this.getCableBus().getLightValue();
if (newLV != this.oldLV) {
this.oldLV = newLV;
this.world.getLightManager().checkBlock(this.pos);
ret = true;
}
this.updateTileSetting();
return ret || c;
}
@Override
protected void writeToStream(final PacketByteBuf data) throws IOException {
super.writeToStream(data);
this.getCableBus().writeToStream(data);
}
/**
* Changes this tile to the TESR version if any of the parts require dynamic
* rendering.
*/
protected void updateTileSetting() {
// FIXME: potentially invalidate voxel shape cache?
}
@Override
public double getMaxRenderDistanceSquared() {
return 900.0;
}
@Override
public void remove() {
super.remove();
this.getCableBus().removeFromWorld();
}
@Override
public void validate() {
super.validate();
TickHandler.INSTANCE.addInit(this);
}
@Override
public IGridNode getGridNode(final AEPartLocation dir) {
return this.getCableBus().getGridNode(dir);
}
@Override
public AECableType getCableConnectionType(final AEPartLocation side) {
return this.getCableBus().getCableConnectionType(side);
}
@Override
public float getCableConnectionLength(AECableType cable) {
return this.getCableBus().getCableConnectionLength(cable);
}
@Override
public void onChunkUnloaded() {
super.onChunkUnloaded();
this.getCableBus().removeFromWorld();
}
@Override
public void markForUpdate() {
if (this.world == null) {
return;
}
final int newLV = this.getCableBus().getLightValue();
if (newLV != this.oldLV) {
this.oldLV = newLV;
this.world.getLightManager().checkBlock(this.pos);
}
super.markForUpdate();
}
@Override
public boolean canBeRotated() {
return false;
}
@Override
public void getDrops(final World w, final BlockPos pos, final List drops) {
this.getCableBus().getDrops(drops);
}
@Override
public void getNoDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
this.getCableBus().getNoDrops(drops);
}
@Override
public void onReady() {
super.onReady();
if (this.getCableBus().isEmpty()) {
if (this.world.getBlockEntity(this.pos) == this) {
this.world.breakBlock(this.pos, true);
}
} else {
this.getCableBus().addToWorld();
}
}
@Override
public IFacadeContainer getFacadeContainer() {
return this.getCableBus().getFacadeContainer();
}
@Override
public boolean canAddPart(final ItemStack is, final AEPartLocation side) {
return this.getCableBus().canAddPart(is, side);
}
@Override
public AEPartLocation addPart(final ItemStack is, final AEPartLocation side, final PlayerEntity player,
final Hand hand) {
return this.getCableBus().addPart(is, side, player, hand);
}
@Override
public IPart getPart(final AEPartLocation side) {
return this.cb.getPart(side);
}
@Override
public IPart getPart(final Direction side) {
return this.getCableBus().getPart(side);
}
@Override
public void removePart(final AEPartLocation side, final boolean suppressUpdate) {
this.getCableBus().removePart(side, suppressUpdate);
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
public AEColor getColor() {
return this.getCableBus().getColor();
}
@Override
public void clearContainer() {
this.setCableBus(new CableBusContainer(this));
}
@Override
public boolean isBlocked(final Direction side) {
// TODO 1.10.2-R - Stuff.
return false;
}
@Override
public SelectedPart selectPart(final Vec3d pos) {
return this.getCableBus().selectPart(pos);
}
@Override
public void markForSave() {
this.saveChanges();
}
@Override
public void partChanged() {
this.notifyNeighbors();
}
@Override
public boolean hasRedstone(final AEPartLocation side) {
return this.getCableBus().hasRedstone(side);
}
@Override
public boolean isEmpty() {
return this.getCableBus().isEmpty();
}
@Override
public Set<LayerFlags> getLayerFlags() {
return this.getCableBus().getLayerFlags();
}
@Override
public void cleanup() {
this.getWorld().removeBlock(this.pos, false);
}
@Override
public void notifyNeighbors() {
if (this.world != null && this.world.isChunkLoaded(this.pos) && !CableBusContainer.isLoading()) {
Platform.notifyBlocksOfNeighbors(this.world, this.pos);
}
}
@Override
public boolean isInWorld() {
return this.getCableBus().isInWorld();
}
@Override
public boolean recolourBlock(final Direction side, final AEColor colour, final PlayerEntity who) {
return this.getCableBus().recolourBlock(side, colour, who);
}
public CableBusContainer getCableBus() {
return this.cb;
}
private void setCableBus(final CableBusContainer cb) {
this.cb = cb;
}
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass, @Nullable Direction fromSide) {
// Note that null will be translated to INTERNAL here
AEPartLocation partLocation = AEPartLocation.fromFacing(fromSide);
IPart part = this.getPart(partLocation);
LazyOptional<T> result = part == null ? LazyOptional.empty() : part.getCapability(capabilityClass);
if (result != null) {
return result;
}
return super.getCapability(capabilityClass, fromSide);
}
@Nonnull
@Override
public CableBusRenderState getRenderAttachmentData() {
World world = getWorld();
if (world == null) {
return EmptyModelData.INSTANCE;
}
CableBusRenderState renderState = this.cb.getRenderState();
renderState.setWorld(world);
renderState.setPos(pos);
return new ModelDataMap.Builder().withInitial(CableBusRenderState.PROPERTY, renderState).build();
}
}
@@ -1,50 +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.tile.networking;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.util.math.Direction;
import appeng.api.parts.IPart;
public class CableBusTESR extends BlockEntityRenderer<CableBusBlockEntity> {
public CableBusTESR(BlockEntityRenderDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
}
@Override
public void render(CableBusBlockEntity te, float partialTicks, MatrixStack ms, VertexConsumerProvider buffers,
int combinedLightIn, int combinedOverlayIn) {
if (!te.getCableBus().isRequiresDynamicRender()) {
return;
}
for (Direction facing : Direction.values()) {
IPart part = te.getPart(facing);
if (part != null && part.requireDynamicRender()) {
part.renderDynamic(partialTicks, ms, buffers, combinedLightIn, combinedOverlayIn);
}
}
}
}
@@ -229,8 +229,8 @@ public abstract class AEBasePoweredBlockEntity extends AEBaseInvBlockEntity
}
@Override
public void remove() {
super.remove();
public void markRemoved() {
super.markRemoved();
// IC2 this.ic2Sink.invalidate();
}
@@ -88,7 +88,7 @@ public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements
}
public void updateRedstoneState() {
final YesNo currentState = this.world.getRedstonePowerFromNeighbors(this.pos) != 0 ? YesNo.YES : YesNo.NO;
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) {
@@ -177,7 +177,7 @@ public class SpatialPylonBlockEntity extends AENetworkBlockEntity implements IAE
final boolean hasLight = this.getLightValue() > 0;
if (hasLight != this.didHaveLight) {
this.didHaveLight = hasLight;
this.world.getLightManager().checkBlock(this.pos);
this.world.getLightingProvider().checkBlock(this.pos);
}
}
@@ -189,7 +189,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO
if (idx > 0) {
--idx;
String itemId = uniqueStrs[idx];
item = ForgeRegistries.ITEMS.getValue(new Identifier(itemId));
item = Registry.ITEM.get(new Identifier(itemId));
}
if (cellItems[i] != item) {
changed = true;
@@ -153,7 +153,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
}
public void updateRedstoneState() {
final YesNo currentState = this.world.getRedstonePowerFromNeighbors(this.pos) != 0 ? YesNo.YES : YesNo.NO;
final YesNo currentState = this.world.getReceivedRedstonePower(this.pos) != 0 ? YesNo.YES : YesNo.NO;
if (this.lastRedstoneState != currentState) {
this.lastRedstoneState = currentState;
this.updateTask();