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
@@ -29,11 +29,13 @@ import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
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.util.IItemProvider;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.item.ItemConvertible;
import net.minecraft.text.Text;
public enum Upgrades {
/**
@@ -48,7 +50,7 @@ public enum Upgrades {
private final int tier;
private final List<Supported> supported = new ArrayList<>();
private List<ITextComponent> supportedTooltipLines;
private List<Text> supportedTooltipLines;
Upgrades(final int tier) {
this.tier = tier;
@@ -62,7 +64,7 @@ public enum Upgrades {
return this.supported;
}
public void registerItem(final IItemProvider item, final int maxSupported) {
public void registerItem(final ItemConvertible item, final int maxSupported) {
this.registerItem(item, maxSupported, null);
}
@@ -76,23 +78,24 @@ public enum Upgrades {
* items have different maxSupported values, the highest
* will be shown.
*/
public void registerItem(final IItemProvider item, final int maxSupported, @Nullable ITextComponent tooltipGroup) {
public void registerItem(final ItemConvertible item, final int maxSupported, @Nullable Text tooltipGroup) {
Preconditions.checkNotNull(item);
this.supported.add(new Supported(item.asItem(), maxSupported, tooltipGroup));
supportedTooltipLines = null; // Reset tooltip
}
public List<ITextComponent> getTooltipLines() {
@Environment(EnvType.CLIENT)
public List<Text> getTooltipLines() {
if (supportedTooltipLines == null) {
supported.sort(Comparator.comparingInt(o -> o.maxCount));
supportedTooltipLines = new ArrayList<>(supported.size());
// Use a separate set because the final text will include numbers
Set<ITextComponent> namesAdded = new HashSet<>();
Set<Text> namesAdded = new HashSet<>();
for (int i = 0; i < supported.size(); i++) {
Supported supported = this.supported.get(i);
ITextComponent name = supported.item.getName();
Text name = supported.item.getName();
// If the group was already added by a previous item, skip this
if (supported.tooltipGroup != null && namesAdded.contains(supported.tooltipGroup)) {
@@ -103,7 +106,7 @@ public enum Upgrades {
// instead
if (supported.tooltipGroup != null) {
for (int j = i + 1; j < this.supported.size(); j++) {
ITextComponent otherGroup = this.supported.get(j).tooltipGroup;
Text otherGroup = this.supported.get(j).tooltipGroup;
if (supported.tooltipGroup.equals(otherGroup)) {
name = supported.tooltipGroup;
break;
@@ -114,7 +117,7 @@ public enum Upgrades {
if (namesAdded.add(name)) {
// append the supported count only if its > 1
if (supported.maxCount > 1) {
name = name.deepCopy().appendText(" (" + supported.maxCount + ")");
name = name.copy().append(" (" + supported.maxCount + ")");
}
supportedTooltipLines.add(name);
}
@@ -133,12 +136,12 @@ public enum Upgrades {
private final Block block;
private final int maxCount;
@Nullable
private final ITextComponent tooltipGroup;
private final Text tooltipGroup;
public Supported(Item item, int maxCount, @Nullable ITextComponent tooltipGroup) {
public Supported(Item item, int maxCount, @Nullable Text tooltipGroup) {
this.item = item;
if (item.getItem() instanceof BlockItem) {
this.block = ((BlockItem) item.getItem()).getBlock();
if (item instanceof BlockItem) {
this.block = ((BlockItem) item).getBlock();
} else {
this.block = null;
}
@@ -30,11 +30,11 @@ import javax.annotation.Nonnull;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IItemProvider;
import net.minecraft.item.ItemConvertible;
import appeng.api.features.AEFeature;
public interface IItemDefinition extends IComparableDefinition, IItemProvider {
public interface IItemDefinition extends IComparableDefinition, ItemConvertible {
/**
* @return the unique name of the definition which will be used to register the
* underlying structure. Will never be null
@@ -45,7 +45,7 @@ import net.minecraft.block.entity.BlockEntity;
* opt-in method. 2. The tile will be removed from the world. 3. Its world,
* coordinates will be changed. *** this can be overridden with a
* IMovableHandler *** 4. It will then be re-added to the world, or a new world.
* 5. TileEntity.validate() 6. IMovableTile.doneMoving ( if you implemented
* 5. TileEntity.cancelRemoval() 6. IMovableTile.doneMoving ( if you implemented
* IMovableTile )
*
* Please note, this is a 100% white list only feature, I will never opt in any
@@ -26,7 +26,7 @@ package appeng.api.networking;
import javax.annotation.Nonnull;
/**
* Allows you to create a network wise service, AE2 uses these for providing
* Allows you to create a network wide service, AE2 uses these for providing
* item, spatial, and tunnel services.
*
* Any Class that implements this, should have a public default constructor that
+15 -2
View File
@@ -47,6 +47,7 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.List;
import java.util.Random;
@@ -230,7 +231,7 @@ public interface IPart extends ICustomCableConnection {
boolean onShiftActivate(PlayerEntity player, Hand hand, Vec3d pos);
/**
* Called when you left click the part, very similar to Block.onBlockClicked
* Called when you left click the part, very similar to Block.onBlockBreakStart
*
* @param player left clicking player
* @param hand hand used
@@ -245,7 +246,7 @@ public interface IPart extends ICustomCableConnection {
/**
* Called when you shift-left click the part, very similar to
* Block.onBlockClicked
* Block.onBlockBreakStart
*
* @param player shift-left clicking player
* @param hand hand used
@@ -344,6 +345,18 @@ public interface IPart extends ICustomCableConnection {
*/
default void addAllAttributes(AttributeList<?> to) {}
/**
* Additional rendering data to be passed to the models for rendering this part.
*
* @return The rendering data to pass to the model. Only useful if custom models are
* used. Can be null to not pass anything.
*/
@Nullable
default Object getModelData() {
return null;
}
/**
* add your collision information to the the list.
*
@@ -30,6 +30,7 @@ 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;
@@ -18,44 +18,6 @@
package appeng.block.networking;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
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.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.DyeColor;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.*;
import net.minecraft.util.hit.HitResult.Type;
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.WorldView;
import net.minecraft.world.World;
import appeng.api.parts.IFacadeContainer;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.PartItemStack;
@@ -66,15 +28,47 @@ 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.sync.network.NetworkHandler;
import appeng.core.sync.packets.ClickPacket;
import appeng.core.AppEng;
import appeng.helpers.AEGlassMaterial;
import appeng.integration.abstraction.IAEFacade;
import appeng.parts.ICableBusContainer;
import appeng.parts.NullCableBusContainer;
import appeng.tile.AEBaseBlockEntity;
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 {
@@ -83,7 +77,23 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
public CableBusBlock() {
super(defaultProps(AEGlassMaterial.INSTANCE)
.nonOpaque()
.dropsNothing().variableOpacity());
.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
@@ -92,15 +102,11 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
}
@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 void onNeighborChange(BlockState state, WorldView w, BlockPos pos, BlockPos neighbor) {
this.cb(w, pos).onneighborUpdate(w, pos, neighbor);
}
@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:
@@ -109,7 +115,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
}
@Override
public boolean canProvidePower(final BlockState state) {
public boolean emitsRedstonePower(final BlockState state) {
return true;
}
@@ -119,57 +125,62 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
}
@Override
public int getStrongPower(final BlockState state, final BlockView w, final BlockPos pos, final Direction side) {
return this.cb(w, pos).isProvidingStrongPower(side.getOpposite()); // TODO:
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
return this.cb(world, pos).isProvidingStrongPower(direction.getOpposite()); // TODO:
// IS
// OPPOSITE!?
}
@Override
public int getLightValue(final BlockState state, final BlockView world, final BlockPos pos) {
if (state.getBlock() != this) {
return state.getLuminance();
}
return this.cb(world, pos).getLightValue();
}
// 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 isLadder(BlockState state, WorldView world, BlockPos pos, LivingEntity entity) {
return this.cb(world, pos).isLadder(entity);
}
@Override
public boolean isReplaceable(BlockState state, ItemPlacementContext useContext) {
public boolean canReplace(BlockState state, ItemPlacementContext context) {
// FIXME: Potentially check the fluid one too
return super.isReplaceable(state, useContext) && this.cb(useContext.getWorld(), useContext.getPos()).isEmpty();
return super.canReplace(state, context) && this.cb(context.getWorld(), context.getBlockPos()).isEmpty();
}
@Override
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player,
boolean willHarvest, IFluidState fluid) {
if (player.abilities.isCreativeMode) {
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
if (tile != null) {
tile.disableDrops();
}
// maybe ray trace?
}
return super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
}
@Override
public boolean canConnectRedstone(final BlockState state, final BlockView w, final BlockPos pos,
Direction side) {
if (side == null) {
side = Direction.UP;
}
// 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 }
return this.cb(w, pos).canConnectRedstone(EnumSet.of(side));
}
// 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 }
@Override
public ItemStack getPickBlock(BlockState state, HitResult target, BlockView world, BlockPos pos,
PlayerEntity player) {
PlayerEntity player) {
final Vec3d v3 = target.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
final SelectedPart sp = this.cb(world, pos).selectPart(v3);
@@ -182,10 +193,11 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
return ItemStack.EMPTY;
}
@Override
// 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) {
final ParticleManager effectRenderer) {
// Half the particle rate. Since we're spawning concentrated on a specific spot,
// our particle effect otherwise looks too strong
@@ -202,7 +214,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
// Our built-in model has the actual baked sprites we need
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager()
.getModelForState(this.getDefaultState());
.getModel(this.getDefaultState());
// We cannot add the effect if we don't have the model
if (!(model instanceof CableBusBakedModel)) {
@@ -222,20 +234,20 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
// FIXME: Check how this looks, probably like shit, maybe provide parts the
// ability to supply particle textures???
effectRenderer
.addEffect(new CableBusBreakingParticle(world, x, y, z, texture).multiplyParticleScaleBy(0.8F));
.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)
@Override
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()
.getModelForState(this.getDefaultState());
.getModel(this.getDefaultState());
// We cannot add the effect if we dont have the model
if (!(model instanceof CableBusBakedModel)) {
@@ -263,9 +275,9 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
// FIXME: Check how this looks, probably like shit, maybe provide parts the
// ability to supply particle textures???
Particle effect = new CableBusBreakingParticle(world, x, y, z, x - pos.getX() - 0.5D,
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.addEffect(effect);
effectRenderer.addParticle(effect);
}
}
}
@@ -276,7 +288,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {
boolean isMoving) {
if (Platform.isServer()) {
this.cb(world, pos).onneighborUpdate(world, pos, fromPos);
}
@@ -305,18 +317,20 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
return out;
}
@Environment(EnvType.CLIENT)
@Override
public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
public void onBlockBreakStart(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
if (worldIn.isClient()) {
final HitResult rtr = MinecraftClient.getInstance().objectMouseOver;
final HitResult rtr = AppEng.instance().getRTR();
if (rtr instanceof BlockHitResult) {
BlockHitResult brtr = (BlockHitResult) rtr;
if (brtr.getPos().equals(pos)) {
final Vec3d hitVec = rtr.getPos().subtract(new Vec3d(pos));
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)) {
NetworkHandler.instance().sendToServer(new ClickPacket(pos, brtr.getSide(), (float) hitVec.x,
(float) hitVec.y, (float) hitVec.z, Hand.MAIN_HAND, true));
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));
}
}
}
@@ -329,7 +343,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
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());
@@ -337,7 +351,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
}
public boolean recolorBlock(final BlockView world, final BlockPos pos, final Direction side,
final DyeColor color, final PlayerEntity who) {
final DyeColor color, final PlayerEntity who) {
try {
return this.cb(world, pos).recolourBlock(side, AEColor.values()[color.ordinal()], who);
} catch (final Throwable ignored) {
@@ -345,12 +359,6 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
return false;
}
@Override
@Environment(EnvType.CLIENT)
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemStacks) {
// do nothing
}
@Override
public BlockState getFacadeState(BlockView world, BlockPos pos, Direction side) {
if (side != null) {
@@ -371,7 +379,7 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
if (te == null) {
return VoxelShapes.empty();
} else {
return te.getCableBus().getShape();
return te.getCableBus().getOutlineShape();
}
}
@@ -381,7 +389,9 @@ public class CableBusBlock extends AEBaseTileBlock<CableBusBlockEntity> implemen
if (te == null) {
return VoxelShapes.empty();
} else {
return te.getCableBus().getCollisionShape(context.getEntity());
Entity entity = null;
// FIXME FABRIC: even EntityShapeContext doesn't give us the actual entity we're colliding with :|
return te.getCableBus().getCollisionShape(entity);
}
}
@@ -24,7 +24,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraft.world.BlockRenderView;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -40,7 +40,7 @@ import appeng.tile.networking.CableBusBlockEntity;
public class CableBusColor implements BlockColorProvider {
@Override
public int getColor(BlockState state, @Nullable ILightReader worldIn, @Nullable BlockPos pos, int color) {
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int color) {
AEColor busColor = AEColor.TRANSPARENT;
@@ -4,17 +4,21 @@ 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;
@@ -60,6 +64,7 @@ public final class AppEngClient extends AppEngBase {
ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
registerModelProviders();
registerParticleRenderers();
registerEntityRenderers();
registerItemColors();
@@ -93,7 +98,7 @@ public final class AppEngClient extends AppEngBase {
@Override
public HitResult getRTR() {
return null;
return client.crosshairTarget;
}
@Override
@@ -103,7 +108,14 @@ public final class AppEngClient extends AppEngBase {
@Override
public CableRenderMode getRenderMode() {
return null;
if (Platform.isServer()) {
return super.getRenderMode();
}
final MinecraftClient mc = MinecraftClient.getInstance();
final PlayerEntity player = mc.player;
return this.renderModeForPlayer(player);
}
public void triggerUpdates() {
@@ -190,4 +202,31 @@ public final class AppEngClient extends AppEngBase {
}
}
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());
}
}
@@ -0,0 +1,367 @@
/*
* 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.render.cablebus;
import appeng.api.parts.IPartModel;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
import net.fabricmc.fabric.impl.client.indigo.renderer.IndigoRenderer;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
import javax.annotation.Nullable;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Supplier;
public class CableBusBakedModel implements BakedModel, FabricBakedModel {
// FIXME: This entire cache seems dumb as shit
private static final Map<CableBusRenderState, Mesh> CABLE_MODEL_CACHE = new HashMap<>();
private final CableBuilder cableBuilder;
private final FacadeBuilder facadeBuilder;
private final Map<Identifier, BakedModel> partModels;
private final Sprite particleTexture;
CableBusBakedModel(CableBuilder cableBuilder, FacadeBuilder facadeBuilder,
Map<Identifier, BakedModel> partModels, Sprite particleTexture) {
this.cableBuilder = cableBuilder;
this.facadeBuilder = facadeBuilder;
this.partModels = partModels;
this.particleTexture = particleTexture;
}
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
// This model will only ever be used for blocks
}
private CableBusRenderState getRenderState(BlockRenderView blockView, BlockPos pos) {
RenderAttachedBlockView renderAttachedBlockView = (RenderAttachedBlockView) blockView;
Object renderAttachment = renderAttachedBlockView.getBlockEntityRenderAttachment(pos);
if (renderAttachment instanceof CableBusRenderState) {
return (CableBusRenderState) renderAttachment;
}
return null;
}
@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
CableBusRenderState renderState = getRenderState(blockView, pos);
if (renderState == null) {
return;
}
RenderLayer layer = RenderLayer.getCutout(); // FIXME: Fabric can only render within one layer (?)
// The core parts of the cable will only be rendered in the CUTOUT layer.
// Facades will add them selves to what ever the block would be rendered with,
// except when transparent facades are enabled, they are forced to TRANSPARENT.
if (layer == RenderLayer.getCutout()) {
// First, handle the cable at the center of the cable bus
final Mesh cableModel = CABLE_MODEL_CACHE.computeIfAbsent(renderState, this::buildCableModel);
if (cableModel != null) {
context.meshConsumer().accept(cableModel);
}
// Then handle attachments
for (Direction facing : Direction.values()) {
final IPartModel partModel = renderState.getAttachments().get(facing);
if (partModel == null) {
continue;
}
Object partModelData = renderState.getPartModelData().get(facing);
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
context.pushTransform(QuadRotator.get(facing, Direction.UP));
if (bakedModel instanceof FabricBakedModel) {
((FabricBakedModel) bakedModel).emitBlockQuads(blockView, state, pos, randomSupplier, context);
} else {
context.fallbackConsumer().accept(bakedModel);
}
context.popTransform();
}
}
}
this.facadeBuilder.buildFacadeQuads(layer, renderState, randomSupplier, context, this.partModels::get);
}
// Determines whether a cable is connected to exactly two sides that are
// opposite each other
private static boolean isStraightLine(AECableType cableType, EnumMap<Direction, AECableType> sides) {
final Iterator<Entry<Direction, AECableType>> it = sides.entrySet().iterator();
if (!it.hasNext()) {
return false; // No connections
}
final Entry<Direction, AECableType> nextConnection = it.next();
final Direction firstSide = nextConnection.getKey();
final AECableType firstType = nextConnection.getValue();
if (!it.hasNext()) {
return false; // Only a single connection
}
if (firstSide.getOpposite() != it.next().getKey()) {
return false; // Connected to two sides that are not opposite each other
}
if (it.hasNext()) {
return false; // Must not have any other connection points
}
final AECableType secondType = sides.get(firstSide.getOpposite());
return firstType == secondType && cableType == firstType && cableType == secondType;
}
private Mesh buildCableModel(CableBusRenderState renderState) {
AECableType cableType = renderState.getCableType();
if (cableType == AECableType.NONE) {
return null;
}
AEColor cableColor = renderState.getCableColor();
EnumMap<Direction, AECableType> connectionTypes = renderState.getConnectionTypes();
MeshBuilder builder = IndigoRenderer.INSTANCE.meshBuilder();
QuadEmitter emitter = builder.getEmitter();
// FIXME
// FIXME // If the connection is straight, no busses are attached, and no covered core
// FIXME // has been forced (in case of glass
// FIXME // cables), then render the cable as a simplified straight line.
// FIXME boolean noAttachments = !renderState.getAttachments().values().stream()
// FIXME .anyMatch(IPartModel::requireCableConnection);
// FIXME if (noAttachments && isStraightLine(cableType, connectionTypes)) {
// FIXME Direction facing = connectionTypes.keySet().iterator().next();
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addStraightGlassConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addStraightCoveredConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addStraightSmartConnection(facing, cableColor,
// FIXME renderState.getChannelsOnSide().get(facing), emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME this.cableBuilder.addStraightDenseCoveredConnection(facing, cableColor, emitter);
// FIXME break;
// FIXME case DENSE_SMART:
// FIXME this.cableBuilder.addStraightDenseSmartConnection(facing, cableColor,
// FIXME renderState.getChannelsOnSide().get(facing), emitter);
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME
// FIXME return null; // Don't render the other form of connection
// FIXME }
// FIXME
// FIXME this.cableBuilder.addCableCore(renderState.getCoreType(), cableColor, emitter);
// FIXME
// FIXME // Render all internal connections to attachments
// FIXME EnumMap<Direction, Integer> attachmentConnections = renderState.getAttachmentConnections();
// FIXME for (Direction facing : attachmentConnections.keySet()) {
// FIXME int distance = attachmentConnections.get(facing);
// FIXME int channels = renderState.getChannelsOnSide().get(facing);
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addConstrainedGlassConnection(facing, cableColor, distance, emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addConstrainedCoveredConnection(facing, cableColor, distance, emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addConstrainedSmartConnection(facing, cableColor, distance, channels, emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME case DENSE_SMART:
// FIXME // Dense cables do not render connections to parts since none can be attached
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME }
// FIXME
// FIXME // Render all outgoing connections using the appropriate type
// FIXME for (final Entry<Direction, AECableType> connection : connectionTypes.entrySet()) {
// FIXME final Direction facing = connection.getKey();
// FIXME final AECableType connectionType = connection.getValue();
// FIXME final boolean cableBusAdjacent = renderState.getCableBusAdjacent().contains(facing);
// FIXME final int channels = renderState.getChannelsOnSide().get(facing);
// FIXME
// FIXME switch (cableType) {
// FIXME case GLASS:
// FIXME this.cableBuilder.addGlassConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case COVERED:
// FIXME this.cableBuilder.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case SMART:
// FIXME this.cableBuilder.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels,
// FIXME emitter);
// FIXME break;
// FIXME case DENSE_COVERED:
// FIXME this.cableBuilder.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME emitter);
// FIXME break;
// FIXME case DENSE_SMART:
// FIXME this.cableBuilder.addDenseSmartConnection(facing, cableColor, connectionType, cableBusAdjacent,
// FIXME channels, emitter);
// FIXME break;
// FIXME default:
// FIXME break;
// FIXME }
// FIXME }
return builder.build();
}
/**
* Gets a list of texture sprites appropriate for particles (digging, etc.)
* given the render state for a cable bus.
*/
public List<Sprite> getParticleTextures(CableBusRenderState renderState) {
CableCoreType coreType = CableCoreType.fromCableType(renderState.getCableType());
AEColor cableColor = renderState.getCableColor();
List<Sprite> result = new ArrayList<>();
if (coreType != null) {
result.add(this.cableBuilder.getCoreTexture(coreType, cableColor));
}
// If no core is present, just use the first part that comes into play
for (Direction side : renderState.getAttachments().keySet()) {
IPartModel partModel = renderState.getAttachments().get(side);
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
Sprite particleTexture = bakedModel.getSprite();
// If a part sub-model has no particle texture (indicated by it being the
// missing texture),
// don't add it, so we don't get ugly missing texture break particles.
if (!isMissingTexture(particleTexture)) {
result.add(particleTexture);
}
}
}
return result;
}
private boolean isMissingTexture(Sprite particleTexture) {
return particleTexture instanceof MissingSprite;
}
@Override
public boolean useAmbientOcclusion() {
return true;
}
@Override
public boolean hasDepth() {
return false;
}
@Override
public boolean isSideLit() {
return false;// TODO
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public Sprite getSprite() {
return this.particleTexture;
}
@Override
public ModelTransformation getTransformation() {
return ModelTransformation.NONE;
}
@Override
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}
public static void clearCache() {
CABLE_MODEL_CACHE.clear();
}
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) {
throw new IllegalStateException();
}
}
@@ -3,7 +3,7 @@ package appeng.client.render.cablebus;
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.particle.SpriteBillboardParticle;
import net.minecraft.client.texture.Sprite;
import net.minecraft.world.World;
import net.minecraft.client.world.ClientWorld;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -15,43 +15,43 @@ public class CableBusBreakingParticle extends SpriteBillboardParticle {
private final float field_217571_C;
private final float field_217572_F;
public CableBusBreakingParticle(World world, double x, double y, double z, double speedX, double speedY,
double speedZ, Sprite sprite) {
public CableBusBreakingParticle(ClientWorld world, double x, double y, double z, double speedX, double speedY,
double speedZ, Sprite sprite) {
super(world, x, y, z, speedX, speedY, speedZ);
this.setSprite(sprite);
this.gravityStrength = 1.0F;
this.particleScale /= 2.0F;
this.field_217571_C = this.rand.nextFloat() * 3.0F;
this.field_217572_F = this.rand.nextFloat() * 3.0F;
this.scale /= 2.0F;
this.field_217571_C = this.random.nextFloat() * 3.0F;
this.field_217572_F = this.random.nextFloat() * 3.0F;
}
public CableBusBreakingParticle(World world, double x, double y, double z, Sprite sprite) {
public CableBusBreakingParticle(ClientWorld world, double x, double y, double z, Sprite sprite) {
this(world, x, y, z, 0, 0, 0, sprite);
}
@Override
public ParticleTextureSheet getRenderType() {
public ParticleTextureSheet getType() {
return ParticleTextureSheet.TERRAIN_SHEET;
}
@Override
protected float getMinU() {
return this.sprite.getInterpolatedU((this.field_217571_C + 1.0F) / 4.0F * 16.0F);
return this.sprite.getFrameU((this.field_217571_C + 1.0F) / 4.0F * 16.0F);
}
@Override
protected float getMaxU() {
return this.sprite.getInterpolatedU(this.field_217571_C / 4.0F * 16.0F);
return this.sprite.getFrameU(this.field_217571_C / 4.0F * 16.0F);
}
@Override
protected float getMinV() {
return this.sprite.getInterpolatedV(this.field_217572_F / 4.0F * 16.0F);
return this.sprite.getFrameV(this.field_217572_F / 4.0F * 16.0F);
}
@Override
protected float getMaxV() {
return this.sprite.getInterpolatedV((this.field_217572_F + 1.0F) / 4.0F * 16.0F);
return this.sprite.getFrameV((this.field_217572_F + 1.0F) / 4.0F * 16.0F);
}
}
@@ -28,24 +28,23 @@ import com.google.common.collect.ImmutableMap;
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.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.UnbakedModel;
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.api.util.AEColor;
import appeng.core.AELog;
import appeng.core.features.registries.PartModels;
import javax.annotation.Nullable;
/**
* The built-in model for the cable bus block.
*/
public class CableBusModel implements IModelGeometry<CableBusModel> {
public class CableBusModel implements UnbakedModel {
private final PartModels partModels;
@@ -54,12 +53,17 @@ public class CableBusModel implements IModelGeometry<CableBusModel> {
}
@Override
public BakedModel bake(IModelConfiguration owner, ModelLoader bakery,
Function<SpriteIdentifier, Sprite> spriteGetter, IModelTransform modelTransform,
ModelOverrideList overrides, Identifier modelLocation) {
Map<Identifier, BakedModel> partModels = this.loadPartModels(bakery, spriteGetter, modelTransform);
public Collection<Identifier> getModelDependencies() {
CableBuilder cableBuilder = new CableBuilder(spriteGetter);
return Collections.emptyList();
}
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
Map<Identifier, BakedModel> partModels = this.loadPartModels(loader, rotationContainer);
CableBuilder cableBuilder = new CableBuilder(textureGetter);
FacadeBuilder facadeBuilder = new FacadeBuilder();
// This should normally not be used, but we *have* to provide a particle texture
@@ -71,17 +75,16 @@ public class CableBusModel implements IModelGeometry<CableBusModel> {
}
@Override
public Collection<SpriteIdentifier> getTextures(IModelConfiguration owner,
Function<Identifier, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) {
return Collections.unmodifiableList(CableBuilder.getTextures());
}
private Map<Identifier, BakedModel> loadPartModels(ModelLoader bakery,
Function<SpriteIdentifier, Sprite> spriteGetterIn, IModelTransform transformIn) {
private Map<Identifier, BakedModel> loadPartModels(ModelLoader loader,
ModelBakeSettings rotationContainer) {
ImmutableMap.Builder<Identifier, BakedModel> result = ImmutableMap.builder();
for (Identifier location : this.partModels.getModels()) {
BakedModel bakedModel = bakery.getBakedModel(location, transformIn, spriteGetterIn);
BakedModel bakedModel = loader.bake(location, rotationContainer);
if (bakedModel == null) {
AELog.warn("Failed to bake part model {}", location);
} else {
@@ -0,0 +1,31 @@
package appeng.client.render.cablebus;
import appeng.core.AppEng;
import appeng.core.features.registries.PartModels;
import net.fabricmc.fabric.api.client.model.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelResourceProvider;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.util.Identifier;
public class CableBusModelLoader implements ModelResourceProvider {
private static final Identifier CABLE_BUS_MODEL = AppEng.makeId("block/cable_bus");
private final PartModels partModels;
public CableBusModelLoader(PartModels partModels) {
this.partModels = partModels;
}
@Override
public UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context) throws ModelProviderException {
if (CABLE_BUS_MODEL.equals(resourceId)) {
CableBusBakedModel.clearCache();
return new CableBusModel(partModels);
} else {
return null;
}
}
}
@@ -28,9 +28,7 @@ import java.util.Objects;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraftforge.client.model.data.ModelProperty;
import net.minecraft.world.BlockRenderView;
import appeng.api.parts.IPartModel;
import appeng.api.util.AECableType;
@@ -42,8 +40,6 @@ import appeng.api.util.AEColor;
*/
public class CableBusRenderState {
public static final ModelProperty<CableBusRenderState> PROPERTY = new ModelProperty<>();
// The cable type used for rendering the outgoing connections to other blocks
// and attached parts
private AECableType cableType = AECableType.NONE;
@@ -80,7 +76,7 @@ public class CableBusRenderState {
private EnumMap<Direction, FacadeRenderState> facades = new EnumMap<>(Direction.class);
// Used for Facades.
private WeakReference<ILightReader> world;
private WeakReference<BlockRenderView> world;
private BlockPos pos;
// Contains the bounding boxes of all parts on the cable bus to allow facades to
@@ -90,7 +86,7 @@ public class CableBusRenderState {
private List<Box> boundingBoxes = new ArrayList<>();
// Additional model data passed to the part models
private EnumMap<Direction, IModelData> partModelData = new EnumMap<>(Direction.class);
private EnumMap<Direction, Object> partModelData = new EnumMap<>(Direction.class);
public CableCoreType getCoreType() {
return this.coreType;
@@ -152,11 +148,11 @@ public class CableBusRenderState {
return this.facades;
}
public ILightReader getWorld() {
public BlockRenderView getWorld() {
return this.world.get();
}
public void setWorld(ILightReader world) {
public void setWorld(BlockRenderView world) {
this.world = new WeakReference<>(world);
}
@@ -172,7 +168,7 @@ public class CableBusRenderState {
return this.boundingBoxes;
}
public EnumMap<Direction, IModelData> getPartModelData() {
public EnumMap<Direction, Object> getPartModelData() {
return this.partModelData;
}
@@ -18,24 +18,27 @@
package appeng.client.render.cablebus;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import com.google.common.base.Preconditions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.impl.client.indigo.renderer.IndigoRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.math.Direction;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
/**
* Builds the quads for a cube.
*/
@Environment(EnvType.CLIENT)
public class CubeBuilder {
private final List<BakedQuad> output;
@@ -46,7 +49,7 @@ public class CubeBuilder {
private final EnumMap<Direction, Vector4f> customUv = new EnumMap<>(Direction.class);
private byte[] uvRotations = new byte[Direction.values().length];
private final byte[] uvRotations = new byte[Direction.values().length];
private int color = 0xFFFFFFFF;
@@ -54,8 +57,21 @@ public class CubeBuilder {
private boolean renderFullBright;
private final MeshBuilder meshBuilder;
private final QuadEmitter emitter;
private int vertexIndex = 0;
public CubeBuilder(List<BakedQuad> output) {
this.output = output;
meshBuilder = IndigoRenderer.INSTANCE.meshBuilder();
emitter = meshBuilder.getEmitter();
emitter.emit();
meshBuilder.build();
ModelHelper.toQuadLists(meshBuilder.build());
}
public CubeBuilder() {
@@ -90,20 +106,19 @@ public class CubeBuilder {
Sprite texture = this.textures.get(face);
BakedQuadBuilder builder = new BakedQuadBuilder(texture);
builder.setQuadOrientation(face);
builder.setQuadTint(-1);
builder.setApplyDiffuseLighting(true);
QuadEmitter emitter = this.emitter;
emitter.colorIndex(-1)
.nominalFace(face);
UvVector uv = new UvVector();
// The user might have set specific UV coordinates for this face
Vector4f customUv = this.customUv.get(face);
if (customUv != null) {
uv.u1 = texture.getInterpolatedU(customUv.getX());
uv.v1 = texture.getInterpolatedV(customUv.getY());
uv.u2 = texture.getInterpolatedU(customUv.getZ());
uv.v2 = texture.getInterpolatedV(customUv.getW());
uv.u1 = texture.getFrameU(customUv.getX());
uv.v1 = texture.getFrameV(customUv.getY());
uv.u2 = texture.getFrameU(customUv.getZ());
uv.v2 = texture.getFrameV(customUv.getW());
} else if (this.useStandardUV) {
uv = this.getStandardUv(face, texture, x1, y1, z1, x2, y2, z2);
} else {
@@ -112,44 +127,54 @@ public class CubeBuilder {
switch (face) {
case DOWN:
this.putVertexTR(builder, face, x2, y1, z1, uv);
this.putVertexBR(builder, face, x2, y1, z2, uv);
this.putVertexBL(builder, face, x1, y1, z2, uv);
this.putVertexTL(builder, face, x1, y1, z1, uv);
this.putVertexTR(face, x2, y1, z1, uv);
this.putVertexBR(face, x2, y1, z2, uv);
this.putVertexBL(face, x1, y1, z2, uv);
this.putVertexTL(face, x1, y1, z1, uv);
break;
case UP:
this.putVertexTL(builder, face, x1, y2, z1, uv);
this.putVertexBL(builder, face, x1, y2, z2, uv);
this.putVertexBR(builder, face, x2, y2, z2, uv);
this.putVertexTR(builder, face, x2, y2, z1, uv);
this.putVertexTL(face, x1, y2, z1, uv);
this.putVertexBL(face, x1, y2, z2, uv);
this.putVertexBR(face, x2, y2, z2, uv);
this.putVertexTR(face, x2, y2, z1, uv);
break;
case NORTH:
this.putVertexBR(builder, face, x2, y2, z1, uv);
this.putVertexTR(builder, face, x2, y1, z1, uv);
this.putVertexTL(builder, face, x1, y1, z1, uv);
this.putVertexBL(builder, face, x1, y2, z1, uv);
this.putVertexBR(face, x2, y2, z1, uv);
this.putVertexTR(face, x2, y1, z1, uv);
this.putVertexTL(face, x1, y1, z1, uv);
this.putVertexBL(face, x1, y2, z1, uv);
break;
case SOUTH:
this.putVertexBL(builder, face, x1, y2, z2, uv);
this.putVertexTL(builder, face, x1, y1, z2, uv);
this.putVertexTR(builder, face, x2, y1, z2, uv);
this.putVertexBR(builder, face, x2, y2, z2, uv);
this.putVertexBL(face, x1, y2, z2, uv);
this.putVertexTL(face, x1, y1, z2, uv);
this.putVertexTR(face, x2, y1, z2, uv);
this.putVertexBR(face, x2, y2, z2, uv);
break;
case WEST:
this.putVertexTL(builder, face, x1, y1, z1, uv);
this.putVertexTR(builder, face, x1, y1, z2, uv);
this.putVertexBR(builder, face, x1, y2, z2, uv);
this.putVertexBL(builder, face, x1, y2, z1, uv);
this.putVertexTL(face, x1, y1, z1, uv);
this.putVertexTR(face, x1, y1, z2, uv);
this.putVertexBR(face, x1, y2, z2, uv);
this.putVertexBL(face, x1, y2, z1, uv);
break;
case EAST:
this.putVertexBR(builder, face, x2, y2, z1, uv);
this.putVertexBL(builder, face, x2, y2, z2, uv);
this.putVertexTL(builder, face, x2, y1, z2, uv);
this.putVertexTR(builder, face, x2, y1, z1, uv);
this.putVertexBR(face, x2, y2, z1, uv);
this.putVertexBL(face, x2, y2, z2, uv);
this.putVertexTL(face, x2, y1, z2, uv);
this.putVertexTR(face, x2, y1, z1, uv);
break;
}
this.output.add(builder.build());
if (renderFullBright) {
// Force Brightness to 15, this is for full bright mode
// this vertex element will only be present in that case
int lightmap = LightmapTextureManager.pack(15, 15);
emitter.lightmap(lightmap, lightmap, lightmap, lightmap);
}
// FIXME: this is unnecessarily inefficient
emitter.emit();
List<BakedQuad>[] quads = ModelHelper.toQuadLists(meshBuilder.build());
this.output.addAll(Arrays.stream(quads).flatMap(Collection::stream).collect(Collectors.toList()));
}
private UvVector getDefaultUv(Direction face, Sprite texture, float x1, float y1, float z1, float x2,
@@ -159,40 +184,40 @@ public class CubeBuilder {
switch (face) {
case DOWN:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(z1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(z2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(z1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(z2 * 16);
break;
case UP:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(z1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(z2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(z1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(z2 * 16);
break;
case NORTH:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case SOUTH:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case WEST:
uv.u1 = texture.getInterpolatedU(z1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(z2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(z1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(z2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case EAST:
uv.u1 = texture.getInterpolatedU(z2 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(z1 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(z2 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(z1 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
}
@@ -204,47 +229,47 @@ public class CubeBuilder {
UvVector uv = new UvVector();
switch (face) {
case DOWN:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(16 - z1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(16 - z2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(16 - z1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(16 - z2 * 16);
break;
case UP:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(z1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(z2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(z1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(z2 * 16);
break;
case NORTH:
uv.u1 = texture.getInterpolatedU(16 - x1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(16 - x2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(16 - x1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(16 - x2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case SOUTH:
uv.u1 = texture.getInterpolatedU(x1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(x2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(x1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(x2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case WEST:
uv.u1 = texture.getInterpolatedU(z1 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(z2 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(z1 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(z2 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
case EAST:
uv.u1 = texture.getInterpolatedU(16 - z2 * 16);
uv.v1 = texture.getInterpolatedV(16 - y1 * 16);
uv.u2 = texture.getInterpolatedU(16 - z1 * 16);
uv.v2 = texture.getInterpolatedV(16 - y2 * 16);
uv.u1 = texture.getFrameU(16 - z2 * 16);
uv.v1 = texture.getFrameV(16 - y1 * 16);
uv.u2 = texture.getFrameU(16 - z1 * 16);
uv.v2 = texture.getFrameV(16 - y2 * 16);
break;
}
return uv;
}
// uv.u1, uv.v1
private void putVertexTL(BakedQuadBuilder builder, Direction face, float x, float y, float z, UvVector uv) {
private void putVertexTL(Direction face, float x, float y, float z, UvVector uv) {
float u, v;
switch (this.uvRotations[face.ordinal()]) {
@@ -267,11 +292,11 @@ public class CubeBuilder {
break;
}
this.putVertex(builder, face, x, y, z, u, v);
this.putVertex(face, x, y, z, u, v);
}
// uv.u2, uv.v1
private void putVertexTR(BakedQuadBuilder builder, Direction face, float x, float y, float z, UvVector uv) {
private void putVertexTR(Direction face, float x, float y, float z, UvVector uv) {
float u, v;
switch (this.uvRotations[face.ordinal()]) {
@@ -293,11 +318,11 @@ public class CubeBuilder {
v = uv.v2;
break;
}
this.putVertex(builder, face, x, y, z, u, v);
this.putVertex(face, x, y, z, u, v);
}
// uv.u2, uv.v2
private void putVertexBR(BakedQuadBuilder builder, Direction face, float x, float y, float z, UvVector uv) {
private void putVertexBR(Direction face, float x, float y, float z, UvVector uv) {
float u;
float v;
@@ -322,11 +347,11 @@ public class CubeBuilder {
break;
}
this.putVertex(builder, face, x, y, z, u, v);
this.putVertex(face, x, y, z, u, v);
}
// uv.u1, uv.v2
private void putVertexBL(BakedQuadBuilder builder, Direction face, float x, float y, float z, UvVector uv) {
private void putVertexBL(Direction face, float x, float y, float z, UvVector uv) {
float u;
float v;
@@ -351,47 +376,20 @@ public class CubeBuilder {
break;
}
this.putVertex(builder, face, x, y, z, u, v);
this.putVertex(face, x, y, z, u, v);
}
private void putVertex(BakedQuadBuilder builder, Direction face, float x, float y, float z, float u, float v) {
VertexFormat format = builder.getVertexFormat();
private void putVertex(Direction face, float x, float y, float z, float u, float v) {
List<VertexFormatElement> elements = format.getElements();
for (int i = 0; i < elements.size(); i++) {
VertexFormatElement e = elements.get(i);
switch (e.getUsage()) {
case POSITION:
builder.put(i, x, y, z);
break;
case NORMAL:
builder.put(i, face.getOffsetX(), face.getOffsetY(), face.getOffsetZ());
break;
case COLOR:
// Color format is RGBA
float r = (this.color >> 16 & 0xFF) / 255f;
float g = (this.color >> 8 & 0xFF) / 255f;
float b = (this.color & 0xFF) / 255f;
float a = (this.color >> 24 & 0xFF) / 255f;
builder.put(i, r, g, b, a);
break;
case UV:
if (e.getIndex() == 0) {
builder.put(i, u, v);
break;
} else if (e.getIndex() == 2 && renderFullBright) {
// Force Brightness to 15, this is for full bright mode
// this vertex element will only be present in that case
final float lightMapU = (float) (15 * 0x20) / 0xFFFF;
final float lightMapV = (float) (15 * 0x20) / 0xFFFF;
builder.put(i, lightMapU, lightMapV);
break;
}
default:
builder.put(i);
break;
}
}
emitter.pos(vertexIndex, x, y, z);
emitter.pos(vertexIndex, face.getOffsetX(), face.getOffsetY(), face.getOffsetZ());
// Color format is RGBA
emitter.spriteColor(vertexIndex, this.color);
emitter.sprite(vertexIndex, 0, u, v);
vertexIndex++;
}
public void setTexture(Sprite texture) {
@@ -26,42 +26,33 @@ import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraft.world.BlockRenderView;
import appeng.api.AEApi;
import appeng.api.util.AEAxisAlignedBB;
import appeng.parts.misc.CableAnchorPart;
import appeng.thirdparty.codechicken.lib.model.CachedFormat;
import appeng.thirdparty.codechicken.lib.model.Quad;
import appeng.thirdparty.codechicken.lib.model.pipeline.BakedPipeline;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadAlphaOverride;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadClamper;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadCornerKicker;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadFaceStripper;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadReInterpolator;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadTinter;
/**
* The FacadeBuilder builds for facades..
*
@@ -88,31 +79,31 @@ public class FacadeBuilder {
new Box(0.0, 0.0, 0.0, THIN_THICKNESS, 1.0, 1.0),
new Box(1.0 - THIN_THICKNESS, 0.0, 0.0, 1.0, 1.0, 1.0) };
private final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> BakedPipeline.builder()
// Clamper is responsible for clamping the vertex to the bounds specified.
.addElement("clamper", QuadClamper.FACTORY)
// Strips faces if they match a mask.
.addElement("face_stripper", QuadFaceStripper.FACTORY)
// Kicks the edge inner corners in, solves Z fighting
.addElement("corner_kicker", QuadCornerKicker.FACTORY)
// Re-Interpolates the UV's for the quad.
.addElement("interp", QuadReInterpolator.FACTORY)
// Tints the quad if we need it to. Disabled by default.
.addElement("tinter", QuadTinter.FACTORY, false)
// Overrides the quad's alpha if we are forcing transparent facades.
.addElement("transparent", QuadAlphaOverride.FACTORY, false, e -> e.setAlphaOverride(0x4C / 255F)).build()//
);
private final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
//FIXME private final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> BakedPipeline.builder()
//FIXME // Clamper is responsible for clamping the vertex to the bounds specified.
//FIXME .addElement("clamper", QuadClamper.FACTORY)
//FIXME // Strips faces if they match a mask.
//FIXME .addElement("face_stripper", QuadFaceStripper.FACTORY)
//FIXME // Kicks the edge inner corners in, solves Z fighting
//FIXME .addElement("corner_kicker", QuadCornerKicker.FACTORY)
//FIXME // Re-Interpolates the UV's for the quad.
//FIXME .addElement("interp", QuadReInterpolator.FACTORY)
//FIXME // Tints the quad if we need it to. Disabled by default.
//FIXME .addElement("tinter", QuadTinter.FACTORY, false)
//FIXME // Overrides the quad's alpha if we are forcing transparent facades.
//FIXME .addElement("transparent", QuadAlphaOverride.FACTORY, false, e -> e.setAlphaOverride(0x4C / 255F)).build()//
//FIXME );
//FIXME private final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
public void buildFacadeQuads(RenderLayer layer, CableBusRenderState renderState, Random rand, List<BakedQuad> quads,
Function<Identifier, BakedModel> modelLookup) {
BakedPipeline pipeline = this.pipelines.get();
Quad collectorQuad = this.collectors.get();
public void buildFacadeQuads(RenderLayer layer, CableBusRenderState renderState, Supplier<Random> rand,
RenderContext context, Function<Identifier, BakedModel> modelLookup) {
//FIXME BakedPipeline pipeline = this.pipelines.get();
//FIXME Quad collectorQuad = this.collectors.get();
boolean transparent = AEApi.instance().partHelper().getCableRenderMode().transparentFacades;
Map<Direction, FacadeRenderState> facadeStates = renderState.getFacades();
List<Box> partBoxes = renderState.getBoundingBoxes();
Set<Direction> sidesWithParts = renderState.getAttachments().keySet();
ILightReader parentWorld = renderState.getWorld();
BlockRenderView parentWorld = renderState.getWorld();
BlockPos pos = renderState.getPos();
BlockColors blockColors = MinecraftClient.getInstance().getBlockColors();
boolean thinFacades = isUseThinFacades(partBoxes);
@@ -123,12 +114,12 @@ public class FacadeBuilder {
FacadeRenderState facadeRenderState = entry.getValue();
boolean renderStilt = !sidesWithParts.contains(side);
if (layer == RenderLayer.getCutout() && renderStilt) {
context.pushTransform(QuadRotator.get(side, Direction.UP));
for (Identifier part : CableAnchorPart.FACADE_MODELS.getModels()) {
BakedModel partModel = modelLookup.apply(part);
QuadRotator rotator = new QuadRotator();
quads.addAll(rotator.rotateQuads(gatherQuads(partModel, null, rand, EmptyModelData.INSTANCE), side,
Direction.UP));
context.fallbackConsumer().accept(partModel);
}
context.popTransform();
}
// If we are forcing transparency and this isn't the Translucent layer.
if (transparent && layer != RenderLayer.getTranslucent()) {
@@ -138,9 +129,10 @@ public class FacadeBuilder {
BlockState blockState = facadeRenderState.getSourceBlock();
// If we aren't forcing transparency let the block decide if it should render.
if (!transparent && layer != null) {
if (!RenderTypeLookup.canRenderInLayer(blockState, layer)) {
continue;
}
// FIXME FABRIC only one layer per block
// FIXME FABRIC if (!RenderLayers.canRenderInLayer(blockState, layer)) {
// FIXME FABRIC continue;
// FIXME FABRIC }
}
Box fullBounds = thinFacades ? THIN_FACADE_BOXES[sideIndex] : THICK_FACADE_BOXES[sideIndex];
@@ -189,94 +181,94 @@ public class FacadeBuilder {
AEAxisAlignedBB cutOutBox = getCutOutBox(facadeBox, partBoxes);
List<Box> holeStrips = getBoxes(facadeBox, cutOutBox, side.getAxis());
ILightReader facadeAccess = new FacadeBlockAccess(parentWorld, pos, side, blockState);
// FIXME BlockRenderView facadeAccess = new FacadeBlockAccess(parentWorld, pos, side, blockState);
BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
BakedModel model = dispatcher.getModelForState(blockState);
IModelData modelData = model.getModelData(facadeAccess, pos, blockState, EmptyModelData.INSTANCE);
List<BakedQuad> modelQuads = new ArrayList<>();
// If we are forcing transparent facades, fake the render layer, and grab all
// quads.
if (transparent || layer == null) {
for (RenderLayer forcedLayer : RenderLayer.getBlockRenderTypes()) {
// Check if the block renders on the layer we want to force.
if (RenderTypeLookup.canRenderInLayer(blockState, forcedLayer)) {
// Force the layer and gather quads.
ForgeHooksClient.setRenderLayer(forcedLayer);
modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
}
}
// Reset.
ForgeHooksClient.setRenderLayer(layer);
} else {
modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
}
// No quads.. Cool, next!
if (modelQuads.isEmpty()) {
continue;
}
// Grab out pipeline elements.
QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
QuadFaceStripper edgeStripper = pipeline.getElement("face_stripper", QuadFaceStripper.class);
QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
QuadCornerKicker kicker = pipeline.getElement("corner_kicker", QuadCornerKicker.class);
// Set global element states.
// calculate the side mask.
int facadeMask = 0;
for (Entry<Direction, FacadeRenderState> ent : facadeStates.entrySet()) {
Direction s = ent.getKey();
if (s.getAxis() != side.getAxis()) {
FacadeRenderState otherState = ent.getValue();
if (!otherState.isTransparent()) {
facadeMask |= 1 << s.ordinal();
}
}
}
// Setup the edge stripper.
edgeStripper.setBounds(fullBounds);
edgeStripper.setMask(facadeMask);
// Setup the kicker.
kicker.setSide(sideIndex);
kicker.setFacadeMask(facadeMask);
kicker.setBox(fullBounds);
kicker.setThickness(thinFacades ? THIN_THICKNESS : THICK_THICKNESS);
for (BakedQuad quad : modelQuads) {
// lookup the format in CachedFormat.
CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);
// If this quad has a tint index, setup the tinter.
if (quad.hasTintIndex()) {
tinter.setTint(blockColors.getColor(blockState, facadeAccess, pos, quad.getColorIndex()));
}
for (Box box : holeStrips) {
// setup the clamper for this box
clamper.setClampBounds(box);
// Reset the pipeline, clears all enabled/disabled states.
pipeline.reset(format);
// Reset out collector.
collectorQuad.reset(format);
// Enable / disable the optional elements
pipeline.setElementState("tinter", quad.hasTintIndex());
pipeline.setElementState("transparent", transparent);
// Prepare the pipeline for a quad.
pipeline.prepare(collectorQuad);
// Pipe our quad into the pipeline.
quad.pipe(pipeline);
// Check if the collector got any data.
if (collectorQuad.full) {
// Add the result.
quads.add(collectorQuad.bake());
}
}
}
// FIXME FABRIC BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
// FIXME FABRIC BakedModel model = dispatcher.getModel(blockState);
// FIXME FABRIC IModelData modelData = model.getModelData(facadeAccess, pos, blockState, EmptyModelData.INSTANCE);
// FIXME FABRIC
// FIXME FABRIC List<BakedQuad> modelQuads = new ArrayList<>();
// FIXME FABRIC // If we are forcing transparent facades, fake the render layer, and grab all
// FIXME FABRIC // quads.
// FIXME FABRIC if (transparent || layer == null) {
// FIXME FABRIC for (RenderLayer forcedLayer : RenderLayer.getBlockRenderTypes()) {
// FIXME FABRIC // Check if the block renders on the layer we want to force.
// FIXME FABRIC if (RenderLayers.canRenderInLayer(blockState, forcedLayer)) {
// FIXME FABRIC // Force the layer and gather quads.
// FIXME FABRIC ForgeHooksClient.setRenderLayer(forcedLayer);
// FIXME FABRIC modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC // Reset.
// FIXME FABRIC ForgeHooksClient.setRenderLayer(layer);
// FIXME FABRIC } else {
// FIXME FABRIC modelQuads.addAll(gatherQuads(model, blockState, rand, modelData));
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC // No quads.. Cool, next!
// FIXME FABRIC if (modelQuads.isEmpty()) {
// FIXME FABRIC continue;
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC // Grab out pipeline elements.
// FIXME FABRIC QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
// FIXME FABRIC QuadFaceStripper edgeStripper = pipeline.getElement("face_stripper", QuadFaceStripper.class);
// FIXME FABRIC QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
// FIXME FABRIC QuadCornerKicker kicker = pipeline.getElement("corner_kicker", QuadCornerKicker.class);
// FIXME FABRIC
// FIXME FABRIC // Set global element states.
// FIXME FABRIC
// FIXME FABRIC // calculate the side mask.
// FIXME FABRIC int facadeMask = 0;
// FIXME FABRIC for (Entry<Direction, FacadeRenderState> ent : facadeStates.entrySet()) {
// FIXME FABRIC Direction s = ent.getKey();
// FIXME FABRIC if (s.getAxis() != side.getAxis()) {
// FIXME FABRIC FacadeRenderState otherState = ent.getValue();
// FIXME FABRIC if (!otherState.isTransparent()) {
// FIXME FABRIC facadeMask |= 1 << s.ordinal();
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC // Setup the edge stripper.
// FIXME FABRIC edgeStripper.setBounds(fullBounds);
// FIXME FABRIC edgeStripper.setMask(facadeMask);
// FIXME FABRIC
// FIXME FABRIC // Setup the kicker.
// FIXME FABRIC kicker.setSide(sideIndex);
// FIXME FABRIC kicker.setFacadeMask(facadeMask);
// FIXME FABRIC kicker.setBox(fullBounds);
// FIXME FABRIC kicker.setThickness(thinFacades ? THIN_THICKNESS : THICK_THICKNESS);
// FIXME FABRIC
// FIXME FABRIC for (BakedQuad quad : modelQuads) {
// FIXME FABRIC // lookup the format in CachedFormat.
// FIXME FABRIC CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
// FIXME FABRIC // If this quad has a tint index, setup the tinter.
// FIXME FABRIC if (quad.hasTintIndex()) {
// FIXME FABRIC tinter.setTint(blockColors.getColor(blockState, facadeAccess, pos, quad.getColorIndex()));
// FIXME FABRIC }
// FIXME FABRIC for (Box box : holeStrips) {
// FIXME FABRIC // setup the clamper for this box
// FIXME FABRIC clamper.setClampBounds(box);
// FIXME FABRIC // Reset the pipeline, clears all enabled/disabled states.
// FIXME FABRIC pipeline.reset(format);
// FIXME FABRIC // Reset out collector.
// FIXME FABRIC collectorQuad.reset(format);
// FIXME FABRIC // Enable / disable the optional elements
// FIXME FABRIC pipeline.setElementState("tinter", quad.hasTintIndex());
// FIXME FABRIC pipeline.setElementState("transparent", transparent);
// FIXME FABRIC // Prepare the pipeline for a quad.
// FIXME FABRIC pipeline.prepare(collectorQuad);
// FIXME FABRIC
// FIXME FABRIC // Pipe our quad into the pipeline.
// FIXME FABRIC quad.pipe(pipeline);
// FIXME FABRIC // Check if the collector got any data.
// FIXME FABRIC if (collectorQuad.full) {
// FIXME FABRIC // Add the result.
// FIXME FABRIC quads.add(collectorQuad.bake());
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC }
}
}
@@ -287,53 +279,54 @@ public class FacadeBuilder {
*/
public List<BakedQuad> buildFacadeItemQuads(ItemStack textureItem, Direction side) {
List<BakedQuad> facadeQuads = new ArrayList<>();
BakedModel model = MinecraftClient.getInstance().getItemRenderer().getItemModelWithOverrides(textureItem, null,
null);
List<BakedQuad> modelQuads = gatherQuads(model, null, new Random(), EmptyModelData.INSTANCE);
BakedPipeline pipeline = this.pipelines.get();
Quad collectorQuad = this.collectors.get();
BakedModel model = MinecraftClient.getInstance().getItemRenderer().getHeldItemModel(textureItem, null,
null);
List<BakedQuad> modelQuads = gatherQuads(model, null, new Random());
//FIXME BakedPipeline pipeline = this.pipelines.get();
//FIXME Quad collectorQuad = this.collectors.get();
// Grab pipeline elements.
QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
// FIXME QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
// FIXME QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
for (BakedQuad quad : modelQuads) {
// Lookup the CachedFormat for this quads format.
CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);
// FIXME CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
// Reset the pipeline.
pipeline.reset(format);
// FIXME pipeline.reset(format);
// Reset the collector.
collectorQuad.reset(format);
//FIXME collectorQuad.reset(format);
// If we have a tint index, setup the tinter and enable it.
if (quad.hasTintIndex()) {
tinter.setTint(MinecraftClient.getInstance().getItemColors().getColor(textureItem, quad.getColorIndex()));
pipeline.enableElement("tinter");
}
// FIXME if (quad.hasTintIndex()) {
// FIXME tinter.setTint(MinecraftClient.getInstance().getItemColors().getColor(textureItem, quad.getColorIndex()));
// FIXME pipeline.enableElement("tinter");
// FIXME }
// Disable elements we don't need for items.
pipeline.disableElement("face_stripper");
pipeline.disableElement("corner_kicker");
// Setup the clamper
clamper.setClampBounds(THICK_FACADE_BOXES[side.ordinal()]);
// Prepare the pipeline.
pipeline.prepare(collectorQuad);
// Pipe our quad into the pipeline.
quad.pipe(pipeline);
// Check the collector for data and add the quad if there was.
if (collectorQuad.full) {
facadeQuads.add(collectorQuad.bake());
}
// FIXME pipeline.disableElement("face_stripper");
// FIXME pipeline.disableElement("corner_kicker");
// FIXME // Setup the clamper
// FIXME clamper.setClampBounds(THICK_FACADE_BOXES[side.ordinal()]);
// FIXME // Prepare the pipeline.
// FIXME pipeline.prepare(collectorQuad);
// FIXME // Pipe our quad into the pipeline.
// FIXME quad.pipe(pipeline);
// FIXME // Check the collector for data and add the quad if there was.
// FIXME if (collectorQuad.full) {
// FIXME facadeQuads.add(collectorQuad.bake());
// FIXME }
}
return facadeQuads;
}
// Helper to gather all quads from a model into a list.
private static List<BakedQuad> gatherQuads(BakedModel model, BlockState state, Random rand, IModelData data) {
private static List<BakedQuad> gatherQuads(BakedModel model, BlockState state, Random rand) {
List<BakedQuad> modelQuads = new ArrayList<>();
for (Direction face : Direction.values()) {
modelQuads.addAll(model.getQuads(state, face, rand, data));
modelQuads.addAll(model.getQuads(state, face, rand));
}
modelQuads.addAll(model.getQuads(state, null, rand, data));
modelQuads.addAll(model.getQuads(state, null, rand));
return modelQuads;
}
@@ -0,0 +1,93 @@
/*
* 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.render.cablebus;
import appeng.client.render.FacingToRotation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f;
/**
* Assuming a default-orientation of forward=NORTH and up=UP, this class rotates
* a given list of quads to the desired facing
*/
@Environment(EnvType.CLIENT)
public class QuadRotator implements RenderContext.QuadTransform {
// FIXME private static final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> //
// FIXME BakedPipeline.builder()//
// FIXME .addElement("transformer", QuadMatrixTransformer.FACTORY)//
// FIXME .build());
// FIXME private static final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
private static final RenderContext.QuadTransform NULL_TRANSFORM = quad -> true;
private final FacingToRotation rotation;
public QuadRotator(FacingToRotation rotation) {
this.rotation = rotation;
}
public static RenderContext.QuadTransform get(Direction newForward, Direction newUp) {
if (newForward == Direction.NORTH && newUp == Direction.UP) {
return NULL_TRANSFORM; // This is the default orientation
}
FacingToRotation rotation = getRotation(newForward, newUp);
if (rotation.isRedundant()) {
return NULL_TRANSFORM;
}
return new QuadRotator(rotation);
}
@Override
public boolean transform(MutableQuadView quad) {
// FIXME: Temporary rotation fix
Matrix4f mat = new Matrix4f();
mat.addToLastColumn(new Vector3f(-0.5f, -0.5f, -0.5f));
mat.multiply(rotation.getMat());
mat.addToLastColumn(new Vector3f(0.5f, 0.5f, 0.5f));
// FIXME ROTATION pipeline.reset(format);
// FIXME ROTATION collector.reset(format);
// FIXME ROTATION
// FIXME ROTATION transformer.setMatrix(mat);
// FIXME ROTATION pipeline.prepare(collector);
// FIXME ROTATION quad.pipe(pipeline);
return true;
}
private static FacingToRotation getRotation(Direction forward, Direction up) {
// Sanitize forward/up
if (forward.getAxis() == up.getAxis()) {
if (up.getAxis() == Direction.Axis.Y) {
up = Direction.NORTH;
} else {
up = Direction.UP;
}
}
return FacingToRotation.get(forward, up);
}
}
@@ -21,6 +21,8 @@ package appeng.client.render.cablebus;
import java.util.Arrays;
import java.util.function.Function;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.texture.Sprite;
@@ -31,6 +33,7 @@ import appeng.core.AppEng;
/**
* Manages the channel textures for smart cables.
*/
@Environment(EnvType.CLIENT)
public class SmartCableTextures {
public static final SpriteIdentifier[] SMART_CHANNELS_TEXTURES = Arrays
+2 -23
View File
@@ -145,27 +145,6 @@ public interface AppEng {
// definitions.getRegistry().getBootstrapComponents(IClientSetupComponent.class)
// .forEachRemaining(IClientSetupComponent::setup);
//
// addBuiltInModel("glass", GlassModel::new);
// addBuiltInModel("sky_compass", SkyCompassModel::new);
// addBuiltInModel("dummy_fluid_item", DummyFluidItemModel::new);
// addBuiltInModel("memory_card", MemoryCardModel::new);
// addBuiltInModel("biometric_card", BiometricCardModel::new);
// addBuiltInModel("drive", DriveModel::new);
// addBuiltInModel("color_applicator", ColorApplicatorModel::new);
// addBuiltInModel("spatial_pylon", SpatialPylonModel::new);
// addBuiltInModel("paint_splotches", PaintSplotchesModel::new);
// addBuiltInModel("quantum_bridge_formed", QnbFormedModel::new);
// addBuiltInModel("p2p_tunnel_frequency", P2PTunnelFrequencyModel::new);
// addBuiltInModel("facade", FacadeItemModel::new);
// ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "encoded_pattern"),
// EncodedPatternModelLoader.INSTANCE);
// ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "part_plane"),
// PlaneModelLoader.INSTANCE);
// ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "crafting_cube"),
// CraftingCubeModelLoader.INSTANCE);
// ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "uvlightmap"), UVLModelLoader.INSTANCE);
// ModelLoaderRegistry.registerLoader(new Identifier(AppEng.MOD_ID, "cable_bus"),
// new CableBusModelLoader((PartModels) Api.INSTANCE.registries().partModels()));
//
// }
//
@@ -214,7 +193,7 @@ public interface AppEng {
////
//// if( Platform.isClient() )
//// {
//// AppEng.proxy.preinit();
//// AppEng.instance().preinit();
//// }
////
//// IntegrationRegistry.INSTANCE.preInit();
@@ -243,7 +222,7 @@ public interface AppEng {
// // FIXME CrashReportExtender.registerCrashCallable( new
// // IntegrationCrashEnhancement() );
//
// AppEng.proxy.postInit();
// AppEng.instance().postInit();
// AEConfig.instance().save();
//
// NetworkHandler.init(new Identifier(MOD_ID, "main"));
+50 -5
View File
@@ -2,6 +2,12 @@ package appeng.core;
import appeng.api.features.IRegistryContainer;
import appeng.api.networking.IGridCacheRegistry;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.CableRenderMode;
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
import appeng.client.render.effects.ParticleTypes;
import appeng.core.features.registries.cell.BasicCellHandler;
@@ -14,10 +20,14 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.network.TargetPoint;
import appeng.hooks.TickHandler;
import appeng.hooks.ToolItemHook;
import appeng.me.cache.*;
import appeng.mixins.CriteriaRegisterMixin;
import appeng.recipes.handlers.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.Identifier;
@@ -28,6 +38,9 @@ public abstract class AppEngBase implements AppEng {
protected AdvancementTriggers advancementTriggers;
// WTF is this doing? Should this be a ThreadLocal???
private PlayerEntity renderModeBased;
public AppEngBase() {
if (AppEng.instance() != null) {
throw new IllegalStateException();
@@ -60,13 +73,13 @@ public abstract class AppEngBase implements AppEng {
final IRegistryContainer registries = api.registries();
final IGridCacheRegistry gcr = registries.gridCache();
// FIXME FABRIC gcr.registerGridCache(ITickManager.class, TickManagerCache.class);
// FIXME FABRIC gcr.registerGridCache(IEnergyGrid.class, EnergyGridCache.class);
// FIXME FABRIC gcr.registerGridCache(IPathingGrid.class, PathGridCache.class);
// FIXME FABRIC gcr.registerGridCache(IStorageGrid.class, GridStorageCache.class);
gcr.registerGridCache(ITickManager.class, TickManagerCache::new);
gcr.registerGridCache(IEnergyGrid.class, EnergyGridCache::new);
gcr.registerGridCache(IPathingGrid.class, PathGridCache::new);
gcr.registerGridCache(IStorageGrid.class, GridStorageCache::new);
// FIXME FABRIC gcr.registerGridCache(P2PCache.class, P2PCache.class);
// FIXME FABRIC gcr.registerGridCache(ISpatialCache.class, SpatialPylonCache.class);
// FIXME FABRIC gcr.registerGridCache(ISecurityGrid.class, SecurityCache.class);
gcr.registerGridCache(ISecurityGrid.class, SecurityCache::new);
// FIXME FABRIC gcr.registerGridCache(ICraftingGrid.class, CraftingGridCache.class);
registries.cell().addCellHandler(new BasicCellHandler());
@@ -130,4 +143,36 @@ public abstract class AppEngBase implements AppEng {
));
}
@Override
public CableRenderMode getRenderMode() {
if (this.renderModeBased == null) {
return CableRenderMode.STANDARD;
}
return this.renderModeForPlayer(this.renderModeBased);
}
// FIXME this is some hot shit _FOR WHAT_?
@Override
public void updateRenderMode(final PlayerEntity player) {
this.renderModeBased = player;
}
protected CableRenderMode renderModeForPlayer(final PlayerEntity player) {
if (player != null) {
for (int x = 0; x < PlayerInventory.getHotbarSize(); x++) {
final ItemStack is = player.inventory.getStack(x);
// FIXME FABRIC if (!is.isEmpty() && is.getItem() instanceof NetworkToolItem) {
// FIXME FABRIC final CompoundTag c = is.getTag();
// FIXME FABRIC if (c != null && c.getBoolean("hideFacades")) {
// FIXME FABRIC return CableRenderMode.CABLE_VIEW;
// FIXME FABRIC }
// FIXME FABRIC }
}
}
return CableRenderMode.STANDARD;
}
}
@@ -18,6 +18,7 @@
package appeng.core.api;
import appeng.parts.PartPlacement;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
@@ -35,8 +36,7 @@ public class ApiPart implements IPartHelper {
@Override
public ActionResult placeBus(final ItemStack is, final BlockPos pos, final Direction side,
final PlayerEntity player, final Hand hand, final World w) {
// FIXME return PartPlacement.place(is, pos, side, player, hand, w, PartPlacement.PlaceType.PLACE_ITEM, 0);
throw new IllegalStateException();
return PartPlacement.place(is, pos, side, player, hand, w, PartPlacement.PlaceType.PLACE_ITEM, 0);
}
@Override
@@ -23,6 +23,8 @@ import appeng.api.definitions.IBlocks;
import appeng.api.definitions.ITileDefinition;
import appeng.api.features.AEFeature;
import appeng.block.misc.*;
import appeng.block.networking.CableBusBlock;
import appeng.block.networking.CableBusRendering;
import appeng.block.storage.SkyChestBlock;
import appeng.bootstrap.*;
import appeng.bootstrap.components.IInitComponent;
@@ -35,6 +37,8 @@ import appeng.entity.TinyTNTPrimedEntity;
import appeng.hooks.TinyTNTDispenseItemBehavior;
import appeng.tile.misc.LightDetectorBlockEntity;
import appeng.tile.misc.SkyCompassBlockEntity;
import appeng.tile.networking.CableBusBlockEntity;
import appeng.tile.networking.CableBusTESR;
import appeng.tile.storage.SkyChestBlockEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -516,16 +520,16 @@ public final class ApiBlocks implements IBlocks {
() -> new AEStairsBlock(this.quartzPillar().block().getDefaultState(), QUARTZ_PROPERTIES))
.addFeatures(AEFeature.CERTUS).build();
// FIXME this.multiPart = registry.block("cable_bus", CableBusBlock::new).rendering(new CableBusRendering())
// FIXME .tileEntity(registry.tileEntity("cable_bus", CableBusBlockEntity.class, CableBusBlockEntity::new)
// FIXME .rendering(new TileEntityRenderingCustomizer<CableBusBlockEntity>() {
// FIXME @Override
// FIXME @Environment(EnvType.CLIENT)
// FIXME public void customize(TileEntityRendering<CableBusBlockEntity> rendering) {
// FIXME rendering.tileEntityRenderer(CableBusTESR::new);
// FIXME }
// FIXME }).build())
// FIXME .build();
this.multiPart = registry.block("cable_bus", CableBusBlock::new).rendering(new CableBusRendering())
.tileEntity(registry.tileEntity("cable_bus", CableBusBlockEntity.class, CableBusBlockEntity::new)
.rendering(new TileEntityRenderingCustomizer<CableBusBlockEntity>() {
@Override
@Environment(EnvType.CLIENT)
public void customize(TileEntityRendering<CableBusBlockEntity> rendering) {
rendering.tileEntityRenderer(CableBusTESR::new);
}
}).build())
.build();
this.skyStoneSlab = deco.block("sky_stone_slab", () -> new SlabBlock(SKYSTONE_PROPERTIES))
.addFeatures(AEFeature.SKY_STONE).build();
@@ -20,9 +20,25 @@ package appeng.core.api.definitions;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IParts;
import appeng.api.parts.IPart;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.bootstrap.FeatureFactory;
import appeng.core.AppEng;
import appeng.core.CreativeTab;
import appeng.core.features.ActivityState;
import appeng.core.features.ColoredItemDefinition;
import appeng.core.features.ItemStackSrc;
import appeng.core.features.registries.PartModels;
import appeng.items.parts.ColoredPartItem;
import appeng.items.parts.PartItem;
import appeng.items.parts.PartItemRendering;
import appeng.parts.misc.CableAnchorPart;
import appeng.parts.networking.*;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import java.util.function.Function;
/**
* Internal implementation for the API parts
@@ -73,110 +89,108 @@ public final class ApiParts implements IParts {
public ApiParts(FeatureFactory registry, PartModels partModels) {
registerPartModels(partModels);
// FIXME this.cableSmart = constructColoredDefinition(registry, "smart_cable", PartType.CABLE_SMART,
// FIXME SmartCablePart::new);
// FIXME this.cableCovered = constructColoredDefinition(registry, "covered_cable", PartType.CABLE_COVERED,
// FIXME CoveredCablePart::new);
// FIXME this.cableGlass = constructColoredDefinition(registry, "glass_cable", PartType.CABLE_GLASS,
// FIXME GlassCablePart::new);
// FIXME this.cableDenseCovered = constructColoredDefinition(registry, "covered_dense_cable",
// FIXME PartType.CABLE_DENSE_COVERED, CoveredDenseCablePart::new);
// FIXME this.cableDenseSmart = constructColoredDefinition(registry, "smart_dense_cable", PartType.CABLE_DENSE_SMART,
// FIXME SmartDenseCablePart::new);
// FIXME this.quartzFiber = createPart(registry, "quartz_fiber", PartType.QUARTZ_FIBER, QuartzFiberPart::new);
// FIXME this.toggleBus = createPart(registry, "toggle_bus", PartType.TOGGLE_BUS, ToggleBusPart::new);
// FIXME this.invertedToggleBus = createPart(registry, "inverted_toggle_bus", PartType.INVERTED_TOGGLE_BUS,
this.cableSmart = constructColoredDefinition(registry, "smart_cable", SmartCablePart::new);
this.cableCovered = constructColoredDefinition(registry, "covered_cable", CoveredCablePart::new);
this.cableGlass = constructColoredDefinition(registry, "glass_cable",
GlassCablePart::new);
this.cableDenseCovered = constructColoredDefinition(registry, "covered_dense_cable",
CoveredDenseCablePart::new);
this.cableDenseSmart = constructColoredDefinition(registry, "smart_dense_cable",
SmartDenseCablePart::new);
this.quartzFiber = createPart(registry, "quartz_fiber", QuartzFiberPart::new);
// FIXME this.toggleBus = createPart(registry, "toggle_bus", ToggleBusPart::new);
// FIXME this.invertedToggleBus = createPart(registry, "inverted_toggle_bus",
// FIXME InvertedToggleBusPart::new);
// FIXME this.cableAnchor = createPart(registry, "cable_anchor", PartType.CABLE_ANCHOR, CableAnchorPart::new);
// FIXME this.monitor = createPart(registry, "monitor", PartType.MONITOR, PanelPart::new);
// FIXME this.semiDarkMonitor = createPart(registry, "semi_dark_monitor", PartType.SEMI_DARK_MONITOR,
this.cableAnchor = createPart(registry, "cable_anchor", CableAnchorPart::new);
// FIXME this.monitor = createPart(registry, "monitor", PanelPart::new);
// FIXME this.semiDarkMonitor = createPart(registry, "semi_dark_monitor",
// FIXME SemiDarkPanelPart::new);
// FIXME this.darkMonitor = createPart(registry, "dark_monitor", PartType.DARK_MONITOR, DarkPanelPart::new);
// FIXME this.storageBus = createPart(registry, "storage_bus", PartType.STORAGE_BUS, StorageBusPart::new);
// FIXME this.fluidStorageBus = createPart(registry, "fluid_storage_bus", PartType.FLUID_STORAGE_BUS,
// FIXME this.darkMonitor = createPart(registry, "dark_monitor", DarkPanelPart::new);
// FIXME this.storageBus = createPart(registry, "storage_bus", StorageBusPart::new);
// FIXME this.fluidStorageBus = createPart(registry, "fluid_storage_bus",
// FIXME FluidStorageBusPart::new);
// FIXME this.importBus = createPart(registry, "import_bus", PartType.IMPORT_BUS, ImportBusPart::new);
// FIXME this.fluidImportBus = createPart(registry, "fluid_import_bus", PartType.FLUID_IMPORT_BUS,
// FIXME this.importBus = createPart(registry, "import_bus", ImportBusPart::new);
// FIXME this.fluidImportBus = createPart(registry, "fluid_import_bus",
// FIXME FluidImportBusPart::new);
// FIXME this.exportBus = createPart(registry, "export_bus", PartType.EXPORT_BUS, ExportBusPart::new);
// FIXME this.fluidExportBus = createPart(registry, "fluid_export_bus", PartType.FLUID_EXPORT_BUS,
// FIXME this.exportBus = createPart(registry, "export_bus", ExportBusPart::new);
// FIXME this.fluidExportBus = createPart(registry, "fluid_export_bus",
// FIXME FluidExportBusPart::new);
// FIXME this.levelEmitter = createPart(registry, "level_emitter", PartType.LEVEL_EMITTER, LevelEmitterPart::new);
// FIXME this.fluidLevelEmitter = createPart(registry, "fluid_level_emitter", PartType.FLUID_LEVEL_EMITTER,
// FIXME this.levelEmitter = createPart(registry, "level_emitter", LevelEmitterPart::new);
// FIXME this.fluidLevelEmitter = createPart(registry, "fluid_level_emitter",
// FIXME FluidLevelEmitterPart::new);
// FIXME this.annihilationPlane = createPart(registry, "annihilation_plane", PartType.ANNIHILATION_PLANE,
// FIXME this.annihilationPlane = createPart(registry, "annihilation_plane",
// FIXME AnnihilationPlanePart::new);
// FIXME this.identityAnnihilationPlane = createPart(registry, "identity_annihilation_plane",
// FIXME PartType.IDENTITY_ANNIHILATION_PLANE, IdentityAnnihilationPlanePart::new);
// FIXME IdentityAnnihilationPlanePart::new);
// FIXME this.fluidAnnihilationPlane = createPart(registry, "fluid_annihilation_plane",
// FIXME PartType.FLUID_ANNIHILATION_PLANE, FluidAnnihilationPlanePart::new);
// FIXME this.formationPlane = createPart(registry, "formation_plane", PartType.FORMATION_PLANE,
// FIXME FluidAnnihilationPlanePart::new);
// FIXME this.formationPlane = createPart(registry, "formation_plane",
// FIXME FormationPlanePart::new);
// FIXME this.fluidFormationPlane = createPart(registry, "fluid_formation_plane", PartType.FLUID_FORMATION_PLANE,
// FIXME this.fluidFormationPlane = createPart(registry, "fluid_formation_plane",
// FIXME FluidFormationPlanePart::new);
// FIXME this.patternTerminal = createPart(registry, "pattern_terminal", PartType.PATTERN_TERMINAL,
// FIXME this.patternTerminal = createPart(registry, "pattern_terminal",
// FIXME PatternTerminalPart::new);
// FIXME this.craftingTerminal = createPart(registry, "crafting_terminal", PartType.CRAFTING_TERMINAL,
// FIXME this.craftingTerminal = createPart(registry, "crafting_terminal",
// FIXME CraftingTerminalPart::new);
// FIXME this.terminal = createPart(registry, "terminal", PartType.TERMINAL, TerminalPart::new);
// FIXME this.storageMonitor = createPart(registry, "storage_monitor", PartType.STORAGE_MONITOR,
// FIXME this.terminal = createPart(registry, "terminal", TerminalPart::new);
// FIXME this.storageMonitor = createPart(registry, "storage_monitor",
// FIXME StorageMonitorPart::new);
// FIXME this.conversionMonitor = createPart(registry, "conversion_monitor", PartType.CONVERSION_MONITOR,
// FIXME this.conversionMonitor = createPart(registry, "conversion_monitor",
// FIXME ConversionMonitorPart::new);
// FIXME this.iface = createPart(registry, "cable_interface", PartType.INTERFACE, InterfacePart::new);
// FIXME this.fluidIface = createPart(registry, "cable_fluid_interface", PartType.FLUID_INTERFACE,
// FIXME this.iface = createPart(registry, "cable_interface", InterfacePart::new);
// FIXME this.fluidIface = createPart(registry, "cable_fluid_interface",
// FIXME FluidInterfacePart::new);
// FIXME this.p2PTunnelME = createPart(registry, "me_p2p_tunnel", PartType.P2P_TUNNEL_ME, MEP2PTunnelPart::new);
// FIXME this.p2PTunnelRedstone = createPart(registry, "redstone_p2p_tunnel", PartType.P2P_TUNNEL_REDSTONE,
// FIXME this.p2PTunnelME = createPart(registry, "me_p2p_tunnel", MEP2PTunnelPart::new);
// FIXME this.p2PTunnelRedstone = createPart(registry, "redstone_p2p_tunnel",
// FIXME RedstoneP2PTunnelPart::new);
// FIXME this.p2PTunnelItems = createPart(registry, "item_p2p_tunnel", PartType.P2P_TUNNEL_ITEM, ItemP2PTunnelPart::new);
// FIXME this.p2PTunnelFluids = createPart(registry, "fluid_p2p_tunnel", PartType.P2P_TUNNEL_FLUID,
// FIXME this.p2PTunnelItems = createPart(registry, "item_p2p_tunnel", ItemP2PTunnelPart::new);
// FIXME this.p2PTunnelFluids = createPart(registry, "fluid_p2p_tunnel",
// FIXME FluidP2PTunnelPart::new);
// FIXME this.p2PTunnelEU = null; // FIXME createPart( "ic2_p2p_tunnel", PartType.P2P_TUNNEL_IC2,
// FIXME this.p2PTunnelEU = null; // FIXME createPart( "ic2_p2p_tunnel",
// FIXME // PartP2PIC2Power::new);
// FIXME this.p2PTunnelFE = createPart(registry, "fe_p2p_tunnel", PartType.P2P_TUNNEL_FE, FEP2PTunnelPart::new);
// FIXME this.p2PTunnelLight = createPart(registry, "light_p2p_tunnel", PartType.P2P_TUNNEL_LIGHT,
// FIXME this.p2PTunnelFE = createPart(registry, "fe_p2p_tunnel", FEP2PTunnelPart::new);
// FIXME this.p2PTunnelLight = createPart(registry, "light_p2p_tunnel",
// FIXME LightP2PTunnelPart::new);
// FIXME this.interfaceTerminal = createPart(registry, "interface_terminal", PartType.INTERFACE_TERMINAL,
// FIXME this.interfaceTerminal = createPart(registry, "interface_terminal",
// FIXME InterfaceTerminalPart::new);
// FIXME this.fluidTerminal = createPart(registry, "fluid_terminal", PartType.FLUID_TERMINAL, FluidTerminalPart::new);
// FIXME this.fluidTerminal = createPart(registry, "fluid_terminal", FluidTerminalPart::new);
}
private void registerPartModels(PartModels partModels) {
// FIXME // Register the built-in models for annihilation planes
// FIXME Identifier fluidFormationPlaneTexture = new Identifier(AppEng.MOD_ID,
// FIXME "item/part/fluid_formation_plane");
// FIXME Identifier fluidFormationPlaneOnTexture = new Identifier(AppEng.MOD_ID,
// FIXME "parts/fluid_formation_plane_on");
// FIXME
// FIXME // Register all part models
// FIXME for (PartType partType : PartType.values()) {
// FIXME partModels.registerModels(partType.getModels());
// FIXME }
// Register the built-in models for annihilation planes
Identifier fluidFormationPlaneTexture = new Identifier(AppEng.MOD_ID,
"item/part/fluid_formation_plane");
Identifier fluidFormationPlaneOnTexture = new Identifier(AppEng.MOD_ID,
"parts/fluid_formation_plane_on");
// Register all part models
// FIXME FABRIC for (PartType partType : PartType.values()) {
// FIXME FABRIC partModels.registerModels(partType.getModels());
// FIXME FABRIC }
}
// FIXME private <T extends IPart> IItemDefinition createPart(FeatureFactory registry, String id, PartType type,
// FIXME Function<ItemStack, T> factory) {
// FIXME return registry.item(id, props -> new PartItem<>(props, type, factory)).itemGroup(CreativeTab.INSTANCE)
// FIXME .rendering(new PartItemRendering()).build();
// FIXME }
// FIXME
// FIXME private <T extends IPart> AEColoredItemDefinition constructColoredDefinition(FeatureFactory registry,
// FIXME String idSuffix, PartType type, Function<ItemStack, T> factory) {
// FIXME final ColoredItemDefinition definition = new ColoredItemDefinition();
// FIXME
// FIXME for (final AEColor color : AEColor.values()) {
// FIXME String id = color.registryPrefix + '_' + idSuffix;
// FIXME
// FIXME IItemDefinition itemDef = registry.item(id, props -> new ColoredPartItem<>(props, type, factory, color))
// FIXME .itemGroup(CreativeTab.INSTANCE).rendering(new PartItemRendering(color)).build();
// FIXME
// FIXME definition.add(color, new ItemStackSrc(itemDef.item(), ActivityState.Enabled));
// FIXME }
// FIXME
// FIXME return definition;
// FIXME }
private <T extends IPart> IItemDefinition createPart(FeatureFactory registry, String id,
Function<ItemStack, T> factory) {
return registry.item(id, props -> new PartItem<>(props, factory)).itemGroup(CreativeTab.INSTANCE)
.rendering(new PartItemRendering()).build();
}
private <T extends IPart> AEColoredItemDefinition constructColoredDefinition(FeatureFactory registry,
String idSuffix, Function<ItemStack, T> factory) {
final ColoredItemDefinition definition = new ColoredItemDefinition();
for (final AEColor color : AEColor.values()) {
String id = color.registryPrefix + '_' + idSuffix;
IItemDefinition itemDef = registry.item(id, props -> new ColoredPartItem<>(props, factory, color))
.itemGroup(CreativeTab.INSTANCE).rendering(new PartItemRendering(color)).build();
definition.add(color, new ItemStackSrc(itemDef.item(), ActivityState.Enabled));
}
return definition;
}
@Override
public AEColoredItemDefinition cableSmart() {
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import appeng.core.sync.packets.PartPlacementPacket;
import appeng.core.sync.packets.SpawnEntityPacket;
import net.minecraft.network.PacketByteBuf;
@@ -40,15 +41,13 @@ public class BasePacketHandler {
// PACKET_ME_FLUID_INVENTORY_UPDATE(MEFluidInventoryUpdatePacket.class, MEFluidInventoryUpdatePacket::new),
//
// PACKET_CONFIG_BUTTON(ConfigButtonPacket.class, ConfigButtonPacket::new),
//
// PACKET_PART_PLACEMENT(PartPlacementPacket.class, PartPlacementPacket::new),
//
PACKET_PART_PLACEMENT(PartPlacementPacket.class, PartPlacementPacket::new),
// PACKET_LIGHTNING(LightningPacket.class, LightningPacket::new),
//
// PACKET_MATTER_CANNON(MatterCannonPacket.class, MatterCannonPacket::new),
//
// PACKET_MOCK_EXPLOSION(MockExplosionPacket.class, MockExplosionPacket::new),
//
// PACKET_VALUE_CONFIG(ConfigValuePacket.class, ConfigValuePacket::new),
//
// PACKET_ITEM_TRANSITION_EFFECT(ItemTransitionEffectPacket.class, ItemTransitionEffectPacket::new),
@@ -21,6 +21,7 @@ public class ServerNetworkHandler implements NetworkHandler {
private final ServerSidePacketRegistry registry = ServerSidePacketRegistry.INSTANCE;
public ServerNetworkHandler() {
NetworkHandlerHolder.INSTANCE = this;
registry.register(BasePacket.CHANNEL, this::handlePacketFromClient);
}
@@ -1,65 +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.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.ParticleTypes;
import net.fabricmc.api.EnvType;
import appeng.core.sync.BasePacket;
import appeng.core.sync.network.INetworkInfo;
public class MockExplosionPacket extends BasePacket {
private final double x;
private final double y;
private final double z;
public MockExplosionPacket(final PacketByteBuf stream) {
this.x = stream.readDouble();
this.y = stream.readDouble();
this.z = stream.readDouble();
}
// api
public MockExplosionPacket(final double x, final double y, final double z) {
this.x = x;
this.y = y;
this.z = z;
final PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
data.writeInt(this.getPacketID());
data.writeDouble(x);
data.writeDouble(y);
data.writeDouble(z);
this.configureWrite(data);
}
@Override
@Environment(EnvType.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
player.world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
@@ -68,11 +68,11 @@ public class PartPlacementPacket extends BasePacket {
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
AppEng.proxy.updateRenderMode(sender);
AppEng.instance().updateRenderMode(sender);
PartPlacement.setEyeHeight(this.eyeHeight);
PartPlacement.place(sender.getStackInHand(this.hand), new BlockPos(this.x, this.y, this.z),
Direction.values()[this.face], sender, this.hand, sender.world,
PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0);
AppEng.proxy.updateRenderMode(null);
AppEng.instance().updateRenderMode(null);
}
}
@@ -116,7 +116,7 @@ public final class GrowingCrystalEntity extends AEBaseItemEntity {
if (this.progress_1000 >= len) {
this.progress_1000 = 0;
// FIXME FABRIC AppEng.proxy.spawnEffect(EffectType.Vibrant, this.world, this.getX(), this.getY() + 0.2,
// FIXME FABRIC AppEng.instance().spawnEffect(EffectType.Vibrant, this.world, this.getX(), this.getY() + 0.2,
// FIXME FABRIC this.getZ(), null);
}
} else {
@@ -21,6 +21,7 @@ package appeng.facade;
import java.io.IOException;
import java.util.Optional;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
@@ -160,7 +161,7 @@ public class FacadeContainer implements IFacadeContainer {
for (int x = 0; x < this.facades; x++) {
final IFacadePart part = this.getFacade(AEPartLocation.fromOrdinal(x));
if (part != null) {
final int itemID = net.minecraft.item.Item.getIdFromItem(part.getItem());
final int itemID = Item.getRawId(part.getItem());
out.writeInt(itemID * (part.notAEFacade() ? -1 : 1));
}
}
@@ -18,12 +18,16 @@
package appeng.items.parts;
import appeng.hooks.AEToolItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.api.EnvironmentInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.item.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tag.BlockTags;
@@ -34,8 +38,7 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.world.EmptyBlockReader;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraft.world.EmptyBlockView;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingDefinitionException;
@@ -48,7 +51,8 @@ import appeng.facade.FacadePart;
import appeng.facade.IFacadeItem;
import appeng.items.AEBaseItem;
public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassItem {
@EnvironmentInterface(value = EnvType.CLIENT, itf=IAlphaPassItem.class)
public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassItem, AEToolItem {
/**
* Block tag used to explicitly whitelist blocks for use in facades.
@@ -72,7 +76,7 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
try {
final ItemStack in = this.getTextureItem(is);
if (!in.isEmpty()) {
return super.getName(is).deepCopy().append(" - ").append(in.getName());
return super.getName(is).copy().append(" - ").append(in.getName());
}
} catch (final Throwable ignored) {
@@ -100,13 +104,13 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
BlockState blockState = block.getDefaultState();
final boolean areTileEntitiesEnabled = AEConfig.instance().isFeatureEnabled(AEFeature.TILE_ENTITY_FACADES);
Tag<Block> whitelistTag = BlockTags.getCollection().getOrCreate(TAG_WHITELISTED);
Tag<Block> whitelistTag = BlockTags.getContainer().getOrCreate(TAG_WHITELISTED);
final boolean isWhiteListed = block.isIn(whitelistTag);
final boolean isModel = blockState.getRenderType() == BlockRenderType.MODEL;
final BlockState defaultState = block.getDefaultState();
final boolean isTileEntity = block.hasTileEntity(defaultState);
final boolean isFullCube = defaultState.isNormalCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO);
final boolean isTileEntity = block.hasBlockEntity();
final boolean isFullCube = defaultState.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
final boolean isTileEntityAllowed = !isTileEntity || (areTileEntitiesEnabled && isWhiteListed);
final boolean isBlockAllowed = isFullCube || isWhiteListed;
@@ -118,7 +122,8 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
final ItemStack is = new ItemStack(this);
final CompoundTag data = new CompoundTag();
data.putString(NBT_ITEM_ID, itemStack.getItem().getRegistryName().toString());
Identifier itemId = Registry.ITEM.getId(itemStack.getItem());
data.putString(NBT_ITEM_ID, itemId.toString());
is.setTag(data);
return is;
}
@@ -143,13 +148,13 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
}
Identifier itemId = new Identifier(nbt.getString(NBT_ITEM_ID));
Item baseItem = ForgeRegistries.ITEMS.getValue(itemId);
Item baseItem = Registry.ITEM.getOrEmpty(itemId).orElse(null);
if (baseItem == null) {
return ItemStack.EMPTY;
}
return new ItemStack(baseItem, 1);
return new ItemStack(baseItem);
}
@Override
@@ -175,18 +180,20 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
() -> new MissingDefinitionException("Tried to create a facade, while facades are being deactivated."));
// Convert back to a registry name...
Item item = Registry.ITEM.getByValue(id);
Item item = Registry.ITEM.get(id);
if (item == Items.AIR) {
return ItemStack.EMPTY;
}
Identifier longId = Registry.ITEM.getId(item);
final CompoundTag facadeTag = new CompoundTag();
facadeTag.putString(NBT_ITEM_ID, item.getRegistryName().toString());
facadeTag.putString(NBT_ITEM_ID, longId.toString());
facadeStack.setTag(facadeTag);
return facadeStack;
}
@Environment(EnvType.CLIENT)
@Override
public boolean useAlphaPass(final ItemStack is) {
BlockState blockState = this.getTextureBlockState(is);
@@ -195,7 +202,7 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte
return false;
}
return RenderTypeLookup.canRenderInLayer(blockState, RenderLayer.getTranslucent())
|| RenderTypeLookup.canRenderInLayer(blockState, RenderLayer.getTranslucentNoCrumbling());
return RenderLayers.getBlockLayer(blockState) == RenderLayer.getTranslucent()
|| RenderLayers.getBlockLayer(blockState) == RenderLayer.getTranslucentNoCrumbling();
}
}
@@ -40,7 +40,7 @@ public class PartItem<T extends IPart> extends AEBaseItem implements IPartItem<T
}
@Override
public ActionResult onItemUse(ItemUsageContext context) {
public ActionResult useOnBlock(ItemUsageContext context) {
PlayerEntity player = context.getPlayer();
ItemStack held = player.getStackInHand(context.getHand());
if (held.getItem() != this) {
+41
View File
@@ -0,0 +1,41 @@
package appeng.me.cache;
import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridStorage;
import javax.annotation.Nonnull;
// FIXME FABRIC DUMMY
public class P2PCache implements IGridCache {
@Override
public void onUpdateTick() {
}
@Override
public void removeNode(@Nonnull IGridNode gridNode, @Nonnull IGridHost machine) {
}
@Override
public void addNode(@Nonnull IGridNode gridNode, @Nonnull IGridHost machine) {
}
@Override
public void onSplit(@Nonnull IGridStorage destinationStorage) {
}
@Override
public void onJoin(@Nonnull IGridStorage sourceStorage) {
}
@Override
public void populateGridStorage(@Nonnull IGridStorage destinationStorage) {
}
}
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Random;
import alexiil.mc.lib.attributes.Simulation;
import com.google.common.base.Preconditions;
import net.fabricmc.api.EnvType;
@@ -324,7 +325,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory(null, target.getSlotCount());
tmp.readFromNBT(compound, "config");
for (int x = 0; x < tmp.getSlotCount(); x++) {
target.setInvStack(x, tmp.getInvStack(x));
target.forceSetInvStack(x, tmp.getInvStack(x));
}
}
}
@@ -362,7 +363,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
}
private boolean useMemoryCard(final PlayerEntity player) {
final ItemStack memCardIS = player.inventory.getCurrentItem();
final ItemStack memCardIS = player.inventory.getMainHandStack();
if (!memCardIS.isEmpty() && this.useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard) {
final IMemoryCard memoryCard = (IMemoryCard) memCardIS.getItem();
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
@@ -42,7 +43,6 @@ import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import appeng.api.AEApi;
import appeng.api.config.YesNo;
@@ -460,7 +460,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
private void updateRedstone() {
final BlockEntity te = this.getTile();
this.hasRedstone = te.getWorld().getRedstonePowerFromNeighbors(te.getPos()) != 0 ? YesNo.YES : YesNo.NO;
this.hasRedstone = te.getWorld().getReceivedRedstonePower(te.getPos()) != 0 ? YesNo.YES : YesNo.NO;
}
private void updateDynamicRender() {
@@ -740,7 +740,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
if (p != null) {
final ItemStack is = p.getItemStack(PartItemStack.NETWORK);
data.writeVarInt(Item.getIdFromItem(is.getItem()));
data.writeVarInt(Item.getRawId(is.getItem()));
p.writeToStream(data);
}
@@ -761,7 +761,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
final int itemID = data.readVarInt();
final Item myItem = Item.getItemById(itemID);
final Item myItem = Item.byRawId(itemID);
final ItemStack current = p != null ? p.getItemStack(PartItemStack.NETWORK) : null;
if (current != null && current.getItem() == myItem) {
@@ -1030,7 +1030,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
World world = getTile().getWorld();
if (blockState != null && textureItem != null && world != null) {
return new FacadeRenderState(blockState,
!facade.getBlockState().isOpaqueCube(world, getTile().getPos()));
!facade.getBlockState().isOpaqueFullCube(world, getTile().getPos()));
}
}
@@ -1038,7 +1038,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
}
/**
* See {@link net.minecraft.block.Block#getShape}
* See {@link net.minecraft.block.Block#getOutlineShape}
*/
public VoxelShape getOutlineShape() {
if (cachedShape == null) {
@@ -1092,7 +1092,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
VoxelShape shape = VoxelShapes.empty();
for (final Box bx : boxes) {
shape = VoxelShapes.or(shape, VoxelShapes.cuboid(bx));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(bx));
}
return shape;
}
@@ -56,9 +56,9 @@ public class CableBusStorage {
if (this.sides != null && this.sides.length > x && part == null) {
this.sides[x] = null;
this.sides = this.decrement(this.sides, true);
this.sides = this.shrink(this.sides, true);
} else if (part != null) {
this.sides = this.expand(this.sides, x, true);
this.sides = this.grow(this.sides, x, true);
this.sides[x] = part;
}
}
@@ -112,9 +112,9 @@ public class CableBusStorage {
public void setFacade(final int x, @Nullable final IFacadePart facade) {
if (this.facades != null && this.facades.length > x && facade == null) {
this.facades[x] = null;
this.facades = this.decrement(this.facades, false);
this.facades = this.shrink(this.facades, false);
} else {
this.facades = this.expand(this.facades, x, false);
this.facades = this.grow(this.facades, x, false);
this.facades[x] = facade;
}
}
@@ -18,63 +18,55 @@
package appeng.parts;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.DirectionalPlaceContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.block.entity.BlockEntity;
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.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.RayTraceContext;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import appeng.api.AEApi;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IItems;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartItem;
import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart;
import appeng.api.parts.*;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ClickPacket;
import appeng.core.sync.packets.PartPlacementPacket;
import appeng.facade.IFacadeItem;
import appeng.util.LookDirection;
import appeng.util.Platform;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RayTraceContext;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class PartPlacement {
private static float eyeHeight = 0.0f;
private final ThreadLocal<Object> placing = new ThreadLocal<>();
private boolean wasCanceled = false;
private static final ThreadLocal<Object> placing = new ThreadLocal<>();
private static boolean wasCanceled = false;
static {
UseBlockCallback.EVENT.register(PartPlacement::onPlayerUseBlock);
}
public static ActionResult place(final ItemStack held, final BlockPos pos, Direction side,
final PlayerEntity player, final Hand hand, final World world, PlaceType pass, final int depth) {
final PlayerEntity player, final Hand hand, final World world, PlaceType pass, final int depth) {
if (depth > 3) {
return ActionResult.FAIL;
}
@@ -158,11 +150,9 @@ public class PartPlacement {
host.markForUpdate();
if (!player.isCreative()) {
held.increment(-1);
;
if (held.getCount() == 0) {
player.inventory.mainInventory.set(player.inventory.currentItem,
player.inventory.main.set(player.inventory.selectedSlot,
ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
}
}
return ActionResult.CONSUME;
@@ -180,7 +170,7 @@ public class PartPlacement {
}
if (held.isEmpty()) {
if (host != null && player.isInSneakingPose() && world.isAirBlock(pos)) {
if (host != null && player.isInSneakingPose() && world.isAir(pos)) {
if (mop.getType() == HitResult.Type.BLOCK) {
Vec3d hitVec = mop.getPos().add(-mop.getPos().getX(), -mop.getPos().getY(),
-mop.getPos().getZ());
@@ -211,7 +201,7 @@ public class PartPlacement {
BlockState blockState = world.getBlockState(pos);
// FIXME isReplacable on the block state allows for more control, but requires
// an item use context
if (!blockState.isAir(world, pos) && !blockState.isReplaceable(useContext)) {
if (!blockState.isAir() && !blockState.canReplace(useContext)) {
offset = side;
if (Platform.isServer()) {
side = side.getOpposite();
@@ -237,7 +227,7 @@ public class PartPlacement {
// We cannot override the item stack of normal use context, so we use this hack
ItemPlacementContext mpUseCtx = new ItemPlacementContext(
new DirectionalPlaceContext(world, te_pos, side, maybeMultiPartStack.get(), side));
new AutomaticItemPlacementContext(world, te_pos, side, maybeMultiPartStack.get(), side));
// FIXME: This is super-fishy and all needs to be re-checked. what does this
// even do???
@@ -273,7 +263,7 @@ public class PartPlacement {
final BlockState blkState = world.getBlockState(te_pos);
// FIXME: this is always true (host was de-referenced above)
if (blkState.isAir(world, te_pos) || blkState.isReplaceable(useContext) || host != null) {
if (blkState.isAir() || blkState.canReplace(useContext) || host != null) {
return place(held, te_pos, side.getOpposite(), player, hand, world,
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS
: PlaceType.PLACE_ITEM,
@@ -304,7 +294,7 @@ public class PartPlacement {
if (mySide != null) {
multiPart.maybeBlock().ifPresent(multiPartBlock -> {
BlockState blockState = world.getBlockState(pos);
final BlockSoundGroup ss = multiPartBlock.getSoundType(blockState, world, pos, player);
final BlockSoundGroup ss = multiPartBlock.getSoundGroup(blockState);
world.playSound(null, pos, ss.getPlaceSound(), SoundCategory.BLOCKS, (ss.getVolume() + 1.0F) / 2.0F,
ss.getPitch() * 0.8F);
@@ -314,7 +304,6 @@ public class PartPlacement {
held.increment(-1);
if (held.getCount() == 0) {
player.setStackInHand(hand, ItemStack.EMPTY);
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
}
}
}
@@ -333,9 +322,9 @@ public class PartPlacement {
}
private static SelectedPart selectPart(final PlayerEntity player, final IPartHost host, final Vec3d pos) {
AppEng.proxy.updateRenderMode(player);
AppEng.instance().updateRenderMode(player);
final SelectedPart sp = host.selectPart(pos);
AppEng.proxy.updateRenderMode(null);
AppEng.instance().updateRenderMode(null);
return sp;
}
@@ -348,65 +337,72 @@ public class PartPlacement {
return null;
}
@SubscribeEvent
public void playerInteract(final TickEvent.ClientTickEvent event) {
this.wasCanceled = false;
private static void playerInteract(final MinecraftClient client) {
wasCanceled = false;
}
@SubscribeEvent
public void playerInteract(final PlayerInteractEvent event) {
// Only handle the main hand event
if (event.getHand() != Hand.MAIN_HAND) {
return;
private static ActionResult onPlayerUseBlock(PlayerEntity player, World world, Hand hand, BlockHitResult hit) {
if (world.isClient || player.isSpectator()) {
return ActionResult.PASS;
}
if (event instanceof PlayerInteractEvent.RightClickEmpty && event.getPlayer().world.isClient) {
// re-check to see if this event was already channeled, cause these two events
// are really stupid...
final HitResult mop = Platform.rayTrace(event.getPlayer(), true, false);
final MinecraftClient mc = MinecraftClient.getInstance();
final float f = 1.0F;
final double d0 = mc.playerController.getBlockReachDistance();
final Vec3d vec3 = mc.getRenderViewEntity().getEyePosition(f);
if (mop instanceof BlockHitResult && mop.getPos().distanceTo(vec3) < d0) {
BlockHitResult brtr = (BlockHitResult) mop;
final World w = event.getEntity().world;
final BlockEntity te = w.getBlockEntity(brtr.getPos());
if (te instanceof IPartHost && this.wasCanceled) {
event.setCanceled(true);
}
} else {
final ItemStack held = event.getPlayer().getStackInHand(event.getHand());
final IItems items = AEApi.instance().definitions().items();
boolean supportedItem = items.memoryCard().isSameAs(held);
supportedItem |= items.colorApplicator().isSameAs(held);
if (event.getPlayer().isInSneakingPose() && !held.isEmpty() && supportedItem) {
NetworkHandler.instance().sendToServer(new ClickPacket(event.getHand()));
}
}
} else if (event instanceof PlayerInteractEvent.RightClickBlock && !event.getPlayer().world.isClient) {
if (this.placing.get() != null) {
return;
}
this.placing.set(event);
final ItemStack held = event.getPlayer().getStackInHand(event.getHand());
if (place(held, event.getPos(), event.getFace(), event.getPlayer(), event.getHand(),
event.getPlayer().world, PlaceType.INTERACT_FIRST_PASS, 0) == ActionResult.SUCCESS) {
event.setCanceled(true);
this.wasCanceled = true;
}
this.placing.set(null);
if (placing.get() != null) {
return ActionResult.PASS;
}
placing.set(true);
final ItemStack held = player.getStackInHand(hand);
if (place(held, hit.getBlockPos(), hit.getSide(), player, hand,
player.world, PlaceType.INTERACT_FIRST_PASS, 0) == ActionResult.SUCCESS) {
return ActionResult.SUCCESS;
}
placing.set(null);
return ActionResult.PASS;
}
// FIXME FABRIC public static void playerInteract(final PlayerInteractEvent event) {
// FIXME FABRIC // Only handle the main hand event
// FIXME FABRIC if (event.getHand() != Hand.MAIN_HAND) {
// FIXME FABRIC return;
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC if (event instanceof PlayerInteractEvent.RightClickEmpty && event.getPlayer().world.isClient) {
// FIXME FABRIC // re-check to see if this event was already channeled, cause these two events
// FIXME FABRIC // are really stupid...
// FIXME FABRIC final HitResult mop = Platform.rayTrace(event.getPlayer(), true, false);
// FIXME FABRIC final MinecraftClient mc = MinecraftClient.getInstance();
// FIXME FABRIC
// FIXME FABRIC final float f = 1.0F;
// FIXME FABRIC final double d0 = mc.playerController.getBlockReachDistance();
// FIXME FABRIC final Vec3d vec3 = mc.getRenderViewEntity().getEyePosition(f);
// FIXME FABRIC
// FIXME FABRIC if (mop instanceof BlockHitResult && mop.getPos().distanceTo(vec3) < d0) {
// FIXME FABRIC BlockHitResult brtr = (BlockHitResult) mop;
// FIXME FABRIC
// FIXME FABRIC final World w = event.getEntity().world;
// FIXME FABRIC final BlockEntity te = w.getBlockEntity(brtr.getPos());
// FIXME FABRIC if (te instanceof IPartHost && this.wasCanceled) {
// FIXME FABRIC event.setCanceled(true);
// FIXME FABRIC }
// FIXME FABRIC } else {
// FIXME FABRIC final ItemStack held = event.getPlayer().getStackInHand(event.getHand());
// FIXME FABRIC final IItems items = AEApi.instance().definitions().items();
// FIXME FABRIC
// FIXME FABRIC boolean supportedItem = items.memoryCard().isSameAs(held);
// FIXME FABRIC supportedItem |= items.colorApplicator().isSameAs(held);
// FIXME FABRIC
// FIXME FABRIC if (event.getPlayer().isInSneakingPose() && !held.isEmpty() && supportedItem) {
// FIXME FABRIC NetworkHandler.instance().sendToServer(new ClickPacket(event.getHand()));
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC } else if (event instanceof PlayerInteractEvent.RightClickBlock && !event.getPlayer().world.isClient) {
// FIXME FABRIC
// FIXME FABRIC }
// FIXME FABRIC }
private static float getEyeHeight() {
return eyeHeight;
}
@@ -27,11 +27,10 @@ import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public class CoveredCablePart extends CablePart {
@Reflected
public CoveredCablePart(final ItemStack is) {
super(is);
}
@@ -31,11 +31,10 @@ import appeng.api.parts.BusSupport;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public abstract class DenseCablePart extends CablePart {
@Reflected
public DenseCablePart(final ItemStack is) {
super(is);
@@ -20,10 +20,8 @@ package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.helpers.Reflected;
public class GlassCablePart extends CablePart {
@Reflected
public GlassCablePart(final ItemStack is) {
super(is);
}
@@ -27,11 +27,10 @@ import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
public class SmartCablePart extends CablePart {
@Reflected
public SmartCablePart(final ItemStack is) {
super(is);
}
@@ -37,6 +37,7 @@ import appeng.util.Platform;
import appeng.util.SettingsFrom;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@@ -55,12 +56,36 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AEBaseBlockEntity extends BlockEntity implements IOrientable, ICommonTile, ICustomNameObject, BlockEntityClientSerializable, RenderAttachmentBlockEntity, AttributeProvider {
// FIXME: should probably remove at start of next server tick!
static {
ServerChunkEvents.CHUNK_UNLOAD.register((serverWorld, worldChunk) -> {
List<AEBaseBlockEntity> entitiesToRemove = null;
for (BlockEntity value : worldChunk.getBlockEntities().values()) {
if (value instanceof AEBaseBlockEntity) {
if (entitiesToRemove == null) {
entitiesToRemove = new ArrayList<>();
}
entitiesToRemove.add((AEBaseBlockEntity) value);
}
}
if (entitiesToRemove != null) {
for (AEBaseBlockEntity blockEntity : entitiesToRemove) {
blockEntity.onChunkUnloaded();
}
}
});
}
protected void onChunkUnloaded() {
}
private static final ThreadLocal<WeakReference<AEBaseBlockEntity>> DROP_NO_ITEMS = new ThreadLocal<>();
private static final Map<Class<? extends BlockEntity>, IStackSrc> ITEM_STACKS = new HashMap<>();
private int renderFragment = 0;
@@ -25,6 +25,7 @@ import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import alexiil.mc.lib.attributes.AttributeList;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
@@ -36,11 +37,6 @@ 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;
@@ -89,7 +85,7 @@ public class CableBusBlockEntity extends AEBaseBlockEntity implements AEMultiTil
final int newLV = this.getCableBus().getLightValue();
if (newLV != this.oldLV) {
this.oldLV = newLV;
this.world.getLightManager().checkBlock(this.pos);
this.world.getLightingProvider().checkBlock(this.pos);
ret = true;
}
@@ -112,19 +108,19 @@ public class CableBusBlockEntity extends AEBaseBlockEntity implements AEMultiTil
}
@Override
public double getMaxRenderDistanceSquared() {
public double getSquaredRenderDistance() {
return 900.0;
}
@Override
public void remove() {
super.remove();
public void markRemoved() {
super.markRemoved();
this.getCableBus().removeFromWorld();
}
@Override
public void validate() {
super.validate();
public void cancelRemoval() {
super.cancelRemoval();
TickHandler.INSTANCE.addInit(this);
}
@@ -158,7 +154,7 @@ public class CableBusBlockEntity extends AEBaseBlockEntity implements AEMultiTil
final int newLV = this.getCableBus().getLightValue();
if (newLV != this.oldLV) {
this.oldLV = newLV;
this.world.getLightManager().checkBlock(this.pos);
this.world.getLightingProvider().checkBlock(this.pos);
}
super.markForUpdate();
@@ -304,32 +300,28 @@ public class CableBusBlockEntity extends AEBaseBlockEntity implements AEMultiTil
}
@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);
public void addAllAttributes(World world, BlockPos pos, BlockState state, AttributeList<?> to) {
super.addAllAttributes(world, pos, state, to);
IPart part = this.getPart(partLocation);
LazyOptional<T> result = part == null ? LazyOptional.empty() : part.getCapability(capabilityClass);
if (result != null) {
return result;
for (AEPartLocation location : AEPartLocation.values()) {
IPart part = this.cb.getPart(location);
if (part != null) {
part.addAllAttributes(to);
}
}
return super.getCapability(capabilityClass, fromSide);
}
@Nonnull
@Override
public CableBusRenderState getRenderAttachmentData() {
World world = getWorld();
if (world == null) {
return EmptyModelData.INSTANCE;
return null;
}
CableBusRenderState renderState = this.cb.getRenderState();
renderState.setWorld(world);
renderState.setPos(pos);
return new ModelDataMap.Builder().withInitial(CableBusRenderState.PROPERTY, renderState).build();
return renderState;
}
}
@@ -1,3 +0,0 @@
{
"loader": "appliedenergistics2:cable_bus"
}
@@ -1,3 +1,2 @@
{
"parent": "appliedenergistics2:block/cable_bus"
}
@@ -109,7 +109,7 @@ public class ChargerBlock extends AEBaseTileBlock<ChargerBlockEntity> {
final double zOff = 0.0;
for (int bolts = 0; bolts < 3; bolts++) {
if (AppEng.proxy.shouldAddParticles(r)) {
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);
}
@@ -71,7 +71,7 @@ public class QuartzGrowthAcceleratorBlock extends AEBaseTileBlock<QuartzGrowthAc
final QuartzGrowthAcceleratorBlockEntity cga = this.getBlockEntity(w, pos);
if (cga != null && cga.isPowered() && AppEng.proxy.shouldAddParticles(r)) {
if (cga != null && cga.isPowered() && AppEng.instance().shouldAddParticles(r)) {
final double d0 = r.nextFloat() - 0.5F;
final double d1 = r.nextFloat() - 0.5F;
@@ -64,8 +64,8 @@ public class QuantumLinkChamberBlock extends QuantumBaseBlock {
final QuantumBridgeBlockEntity bridge = this.getBlockEntity(w, pos);
if (bridge != null) {
if (bridge.hasQES()) {
if (AppEng.proxy.shouldAddParticles(rand)) {
AppEng.proxy.spawnEffect(EffectType.Energy, w, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
if (AppEng.instance().shouldAddParticles(rand)) {
AppEng.instance().spawnEffect(EffectType.Energy, w, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
null);
}
}
@@ -44,7 +44,7 @@ class NullSpatialDimension implements ISpatialDimension {
@Override
public BlockPos getCellDimensionSize(DimensionType cellDim) {
return BlockPos.ZERO;
return BlockPos.ORIGIN;
}
@Override
+1 -18
View File
@@ -113,27 +113,10 @@ public class ClientHelper extends ServerHelper {
}
}
@Override
public HitResult getRTR() {
return MinecraftClient.getInstance().objectMouseOver;
}
@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);
}
private void postPlayerRender(final RenderLivingEvent.Pre p) {
// FIXME final PlayerColor player = TickHandler.INSTANCE.getPlayerColors().get( p.getEntity().getEntityId() );
@@ -149,7 +132,7 @@ public class ClientHelper extends ServerHelper {
}
private void spawnVibrant(final World w, final double x, final double y, final double z) {
if (AppEng.proxy.shouldAddParticles(Platform.getRandom())) {
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;
@@ -31,6 +31,7 @@ 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;
@@ -44,7 +45,6 @@ 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.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -692,7 +692,7 @@ public abstract class AEBaseScreen<T extends AEBaseContainer> extends ContainerS
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
vb.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEX_COLOR);
final float f1 = 0.00390625F;
final float f = 0.00390625F;
@@ -183,7 +183,7 @@ public class InterfaceTerminalScreen extends AEBaseScreen<InterfaceTerminalConta
InputUtil.Key input = InputMappings.getInputByCode(keyCode, scanCode);
if (keyCode != GLFW.GLFW_KEY_ESCAPE) {
if (AppEng.proxy.isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
if (AppEng.instance().isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
this.searchField.setFocused2(!this.searchField.isFocused());
return true;
}
@@ -387,7 +387,7 @@ public class MEMonitorableScreen<T extends MEMonitorableContainer> extends AEBas
InputUtil.Key input = InputMappings.getInputByCode(keyCode, scanCode);
if (keyCode != GLFW.GLFW_KEY_ESCAPE && !this.checkHotbarKeys(input)) {
if (AppEng.proxy.isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
if (AppEng.instance().isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
this.searchField.setFocused2(!this.searchField.isFocused());
return true;
}
@@ -87,7 +87,7 @@ public class QuartzKnifeScreen extends AEBaseScreen<QuartzKnifeContainer> {
InputUtil.Key input = InputMappings.getInputByCode(keyCode, scanCode);
if (keyCode != GLFW.GLFW_KEY_ESCAPE && !this.checkHotbarKeys(input)) {
if (AppEng.proxy.isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
if (AppEng.instance().isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
this.name.setFocused2(!this.name.isFocused());
return true;
}
@@ -23,9 +23,9 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
/**
* A modified version of the Minecraft text field. You can initialize it over
@@ -138,7 +138,7 @@ public class AETextField extends TextFieldWidget {
RenderSystem.disableTexture();
RenderSystem.enableColorLogicOp();
RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.begin(7, VertexFormats.POSITION);
bufferbuilder.pos(startX, endY, 0.0D).endVertex();
bufferbuilder.pos(endX, endY, 0.0D).endVertex();
bufferbuilder.pos(endX, startY, 0.0D).endVertex();
@@ -24,7 +24,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraft.world.BlockRenderView;
import appeng.api.implementations.tiles.IColorableTile;
import appeng.api.util.AEColor;
@@ -37,7 +37,7 @@ public class ColorableTileBlockColor implements BlockColorProvider {
public static final ColorableTileBlockColor INSTANCE = new ColorableTileBlockColor();
@Override
public int getColor(BlockState state, @Nullable ILightReader worldIn, @Nullable BlockPos pos, int tintIndex) {
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int tintIndex) {
AEColor color = AEColor.TRANSPARENT; // Default to a neutral color
if (worldIn != null && pos != null) {
@@ -22,9 +22,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
@@ -42,36 +46,27 @@ import appeng.client.render.cablebus.FacadeBuilder;
*
* @author covers1624
*/
public class FacadeBakedItemModel extends DelegateBakedModel {
public class FacadeBakedItemModel extends ForwardingBakedModel implements FabricBakedModel {
private final ItemStack textureStack;
private final FacadeBuilder facadeBuilder;
private List<BakedQuad> quads = null;
protected FacadeBakedItemModel(BakedModel base, ItemStack textureStack, FacadeBuilder facadeBuilder) {
super(base);
this.wrapped = base;
this.textureStack = textureStack;
this.facadeBuilder = facadeBuilder;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
}
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
super.emitItemQuads(stack, randomSupplier, context);
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
IModelData data) {
if (side != null) {
return Collections.emptyList();
}
if (quads == null) {
quads = new ArrayList<>();
quads.addAll(this.facadeBuilder.buildFacadeItemQuads(this.textureStack, Direction.NORTH));
quads.addAll(this.getBaseModel().getQuads(state, side, rand, data));
quads = Collections.unmodifiableList(quads);
}
return quads;
}
@Override
@@ -20,6 +20,7 @@ package appeng.client.render;
import java.util.Random;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
@@ -30,7 +31,6 @@ import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.math.Quaternion;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.world.ClientWorld;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.client.SkyRenderHandler;
@@ -85,7 +85,7 @@ public class SpatialSkyRender implements SkyRenderHandler {
matrixStack.multiply(rotation);
RenderSystem.disableTexture();
VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
VertexBuffer.begin(GL11.GL_QUADS, VertexFormats.POSITION);
VertexBuffer.pos(-100.0D, -100.0D, -100.0D).endVertex();
VertexBuffer.pos(-100.0D, -100.0D, 100.0D).endVertex();
VertexBuffer.pos(100.0D, -100.0D, 100.0D).endVertex();
@@ -123,7 +123,7 @@ public class SpatialSkyRender implements SkyRenderHandler {
private void renderTwinkles() {
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
vb.begin(GL11.GL_QUADS, VertexFormats.POSITION);
for (int i = 0; i < 50; ++i) {
double iX = this.random.nextFloat() * 2.0F - 1.0F;
@@ -23,7 +23,7 @@ import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraft.world.BlockRenderView;
import appeng.api.util.AEColor;
@@ -39,7 +39,7 @@ public class StaticBlockColor implements BlockColorProvider {
}
@Override
public int getColor(BlockState state, @Nullable ILightReader worldIn, @Nullable BlockPos pos, int tintIndex) {
public int getColor(BlockState state, @Nullable BlockRenderView worldIn, @Nullable BlockPos pos, int tintIndex) {
return this.color.getVariantByTintIndex(tintIndex);
}
@@ -1,348 +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.render.cablebus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.renderer.texture.MissingTextureSprite;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.data.EmptyModelData;
import appeng.api.parts.IPartModel;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
public class CableBusBakedModel implements BakedModel {
private static final Map<CableBusRenderState, List<BakedQuad>> CABLE_MODEL_CACHE = new HashMap<>();
private final CableBuilder cableBuilder;
private final FacadeBuilder facadeBuilder;
private final Map<Identifier, BakedModel> partModels;
private final Sprite particleTexture;
CableBusBakedModel(CableBuilder cableBuilder, FacadeBuilder facadeBuilder,
Map<Identifier, BakedModel> partModels, Sprite particleTexture) {
this.cableBuilder = cableBuilder;
this.facadeBuilder = facadeBuilder;
this.partModels = partModels;
this.particleTexture = particleTexture;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
IModelData data) {
CableBusRenderState renderState = data.getData(CableBusRenderState.PROPERTY);
if (renderState == null || side != null) {
return Collections.emptyList();
}
RenderLayer layer = MinecraftForgeClient.getRenderLayer();
List<BakedQuad> quads = new ArrayList<>();
// The core parts of the cable will only be rendered in the CUTOUT layer.
// Facades will add them selves to what ever the block would be rendered with,
// except when transparent facades are enabled, they are forced to TRANSPARENT.
if (layer == RenderLayer.getCutout()) {
// First, handle the cable at the center of the cable bus
final List<BakedQuad> cableModel = CABLE_MODEL_CACHE.computeIfAbsent(renderState, k -> {
final List<BakedQuad> model = new ArrayList<>();
this.addCableQuads(renderState, model);
return model;
});
quads.addAll(cableModel);
// Then handle attachments
for (Direction facing : Direction.values()) {
final IPartModel partModel = renderState.getAttachments().get(facing);
if (partModel == null) {
continue;
}
IModelData partModelData = renderState.getPartModelData().get(facing);
if (partModelData == null) {
partModelData = EmptyModelData.INSTANCE;
}
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
List<BakedQuad> partQuads = bakedModel.getQuads(state, null, rand, partModelData);
// Rotate quads accordingly
QuadRotator rotator = new QuadRotator();
partQuads = rotator.rotateQuads(partQuads, facing, Direction.UP);
quads.addAll(partQuads);
}
}
}
this.facadeBuilder.buildFacadeQuads(layer, renderState, rand, quads, this.partModels::get);
return quads;
}
// Determines whether a cable is connected to exactly two sides that are
// opposite each other
private static boolean isStraightLine(AECableType cableType, EnumMap<Direction, AECableType> sides) {
final Iterator<Entry<Direction, AECableType>> it = sides.entrySet().iterator();
if (!it.hasNext()) {
return false; // No connections
}
final Entry<Direction, AECableType> nextConnection = it.next();
final Direction firstSide = nextConnection.getKey();
final AECableType firstType = nextConnection.getValue();
if (!it.hasNext()) {
return false; // Only a single connection
}
if (firstSide.getOpposite() != it.next().getKey()) {
return false; // Connected to two sides that are not opposite each other
}
if (it.hasNext()) {
return false; // Must not have any other connection points
}
final AECableType secondType = sides.get(firstSide.getOpposite());
return firstType == secondType && cableType == firstType && cableType == secondType;
}
private void addCableQuads(CableBusRenderState renderState, List<BakedQuad> quadsOut) {
AECableType cableType = renderState.getCableType();
if (cableType == AECableType.NONE) {
return;
}
AEColor cableColor = renderState.getCableColor();
EnumMap<Direction, AECableType> connectionTypes = renderState.getConnectionTypes();
// If the connection is straight, no busses are attached, and no covered core
// has been forced (in case of glass
// cables), then render the cable as a simplified straight line.
boolean noAttachments = !renderState.getAttachments().values().stream()
.anyMatch(IPartModel::requireCableConnection);
if (noAttachments && isStraightLine(cableType, connectionTypes)) {
Direction facing = connectionTypes.keySet().iterator().next();
switch (cableType) {
case GLASS:
this.cableBuilder.addStraightGlassConnection(facing, cableColor, quadsOut);
break;
case COVERED:
this.cableBuilder.addStraightCoveredConnection(facing, cableColor, quadsOut);
break;
case SMART:
this.cableBuilder.addStraightSmartConnection(facing, cableColor,
renderState.getChannelsOnSide().get(facing), quadsOut);
break;
case DENSE_COVERED:
this.cableBuilder.addStraightDenseCoveredConnection(facing, cableColor, quadsOut);
break;
case DENSE_SMART:
this.cableBuilder.addStraightDenseSmartConnection(facing, cableColor,
renderState.getChannelsOnSide().get(facing), quadsOut);
break;
default:
break;
}
return; // Don't render the other form of connection
}
this.cableBuilder.addCableCore(renderState.getCoreType(), cableColor, quadsOut);
// Render all internal connections to attachments
EnumMap<Direction, Integer> attachmentConnections = renderState.getAttachmentConnections();
for (Direction facing : attachmentConnections.keySet()) {
int distance = attachmentConnections.get(facing);
int channels = renderState.getChannelsOnSide().get(facing);
switch (cableType) {
case GLASS:
this.cableBuilder.addConstrainedGlassConnection(facing, cableColor, distance, quadsOut);
break;
case COVERED:
this.cableBuilder.addConstrainedCoveredConnection(facing, cableColor, distance, quadsOut);
break;
case SMART:
this.cableBuilder.addConstrainedSmartConnection(facing, cableColor, distance, channels, quadsOut);
break;
case DENSE_COVERED:
case DENSE_SMART:
// Dense cables do not render connections to parts since none can be attached
break;
default:
break;
}
}
// Render all outgoing connections using the appropriate type
for (final Entry<Direction, AECableType> connection : connectionTypes.entrySet()) {
final Direction facing = connection.getKey();
final AECableType connectionType = connection.getValue();
final boolean cableBusAdjacent = renderState.getCableBusAdjacent().contains(facing);
final int channels = renderState.getChannelsOnSide().get(facing);
switch (cableType) {
case GLASS:
this.cableBuilder.addGlassConnection(facing, cableColor, connectionType, cableBusAdjacent,
quadsOut);
break;
case COVERED:
this.cableBuilder.addCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
quadsOut);
break;
case SMART:
this.cableBuilder.addSmartConnection(facing, cableColor, connectionType, cableBusAdjacent, channels,
quadsOut);
break;
case DENSE_COVERED:
this.cableBuilder.addDenseCoveredConnection(facing, cableColor, connectionType, cableBusAdjacent,
quadsOut);
break;
case DENSE_SMART:
this.cableBuilder.addDenseSmartConnection(facing, cableColor, connectionType, cableBusAdjacent,
channels, quadsOut);
break;
default:
break;
}
}
}
/**
* Gets a list of texture sprites appropriate for particles (digging, etc.)
* given the render state for a cable bus.
*/
public List<Sprite> getParticleTextures(CableBusRenderState renderState) {
CableCoreType coreType = CableCoreType.fromCableType(renderState.getCableType());
AEColor cableColor = renderState.getCableColor();
List<Sprite> result = new ArrayList<>();
if (coreType != null) {
result.add(this.cableBuilder.getCoreTexture(coreType, cableColor));
}
// If no core is present, just use the first part that comes into play
for (Direction side : renderState.getAttachments().keySet()) {
IPartModel partModel = renderState.getAttachments().get(side);
for (Identifier model : partModel.getModels()) {
BakedModel bakedModel = this.partModels.get(model);
if (bakedModel == null) {
throw new IllegalStateException("Trying to use an unregistered part model: " + model);
}
Sprite particleTexture = bakedModel.getSprite();
// If a part sub-model has no particle texture (indicated by it being the
// missing texture),
// don't add it, so we don't get ugly missing texture break particles.
if (!isMissingTexture(particleTexture)) {
result.add(particleTexture);
}
}
}
return result;
}
private boolean isMissingTexture(Sprite particleTexture) {
return particleTexture instanceof MissingTextureSprite;
}
@Override
public boolean useAmbientOcclusion() {
return true;
}
@Override
public boolean hasDepth() {
return false;
}
@Override
public boolean isSideLit() {
return false;// TODO
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public Sprite getSprite() {
return this.particleTexture;
}
@Override
public ModelTransformation getTransformation() {
return ModelTransformation.DEFAULT;
}
@Override
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}
public static void clearCache() {
CABLE_MODEL_CACHE.clear();
}
}
@@ -1,29 +0,0 @@
package appeng.client.render.cablebus;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.resources.IResourceManager;
import net.minecraftforge.client.model.IModelLoader;
import appeng.core.features.registries.PartModels;
public class CableBusModelLoader implements IModelLoader<CableBusModel> {
private final PartModels partModels;
public CableBusModelLoader(PartModels partModels) {
this.partModels = partModels;
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
CableBusBakedModel.clearCache();
}
@Override
public CableBusModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
return new CableBusModel(partModels);
}
}
@@ -25,7 +25,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.IFluidState;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.lighting.WorldLightManager;
@@ -35,14 +35,14 @@ import net.minecraft.world.lighting.WorldLightManager;
*
* @author covers1624
*/
public class FacadeBlockAccess implements ILightReader {
public class FacadeBlockAccess implements BlockRenderView {
private final ILightReader world;
private final BlockRenderView world;
private final BlockPos pos;
private final Direction side;
private final BlockState state;
public FacadeBlockAccess(ILightReader world, BlockPos pos, Direction side, BlockState state) {
public FacadeBlockAccess(BlockRenderView world, BlockPos pos, Direction side, BlockState state) {
this.world = world;
this.pos = pos;
this.side = side;
@@ -69,8 +69,8 @@ public class FacadeBlockAccess implements ILightReader {
}
@Override
public WorldLightManager getLightManager() {
return world.getLightManager();
public WorldLightManager getLightingProvider() {
return world.getLightingProvider();
}
@Override
@@ -9,18 +9,17 @@ import java.util.concurrent.ExecutionException;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.math.Direction;
import net.minecraftforge.client.model.data.IDynamicBakedModel;
import appeng.api.util.AEColor;
import appeng.util.Platform;
public class P2PTunnelFrequencyBakedModel implements IDynamicBakedModel {
public class P2PTunnelFrequencyBakedModel implements FabricBakedModel {
private final Sprite texture;
@@ -1,94 +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.render.cablebus;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Direction;
import appeng.client.render.FacingToRotation;
import appeng.thirdparty.codechicken.lib.model.CachedFormat;
import appeng.thirdparty.codechicken.lib.model.Quad;
import appeng.thirdparty.codechicken.lib.model.pipeline.BakedPipeline;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadMatrixTransformer;
/**
* Assuming a default-orientation of forward=NORTH and up=UP, this class rotates
* a given list of quads to the desired facing
*/
public class QuadRotator {
private static final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> //
BakedPipeline.builder()//
.addElement("transformer", QuadMatrixTransformer.FACTORY)//
.build());
private static final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
public List<BakedQuad> rotateQuads(List<BakedQuad> quads, Direction newForward, Direction newUp) {
if (newForward == Direction.NORTH && newUp == Direction.UP) {
return quads; // This is the default orientation
}
FacingToRotation rotation = getRotation(newForward, newUp);
if (rotation.isRedundant()) {
return quads;
}
List<BakedQuad> result = new ArrayList<>(quads.size());
CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);
BakedPipeline pipeline = pipelines.get();
Quad collector = collectors.get();
QuadMatrixTransformer transformer = pipeline.getElement("transformer", QuadMatrixTransformer.class);
// FIXME: Temporary rotation fix
Matrix4f mat = new Matrix4f();
mat.setTranslation(-0.5f, -0.5f, -0.5f);
mat.multiplyBackward(rotation.getMat());
mat.translate(new Vector3f(0.5f, 0.5f, 0.5f));
for (BakedQuad quad : quads) {
pipeline.reset(format);
collector.reset(format);
transformer.setMatrix(mat);
pipeline.prepare(collector);
quad.pipe(pipeline);
result.add(collector.bake());
}
return result;
}
private FacingToRotation getRotation(Direction forward, Direction up) {
// Sanitize forward/up
if (forward.getAxis() == up.getAxis()) {
if (up.getAxis() == Direction.Axis.Y) {
up = Direction.NORTH;
} else {
up = Direction.UP;
}
}
return FacingToRotation.get(forward, up);
}
}
@@ -32,18 +32,18 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormatElement;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.ILightReader;
import net.minecraft.world.BlockRenderView;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
@@ -174,8 +174,8 @@ public class AutoRotatingBakedModel implements BakedModel {
@Nonnull
@Override
public IModelData getModelData(@Nonnull ILightReader world, @Nonnull BlockPos pos, @Nonnull BlockState state,
@Nonnull IModelData tileData) {
public IModelData getModelData(@Nonnull BlockRenderView world, @Nonnull BlockPos pos, @Nonnull BlockState state,
@Nonnull IModelData tileData) {
return this.parent.getModelData(world, pos, state, tileData);
}
@@ -205,9 +205,9 @@ public class AutoRotatingBakedModel implements BakedModel {
for (int v = 0; v < 4; v++) {
for (int e = 0; e < elements.size(); e++) {
VertexFormatElement element = elements.get(e);
if (element.getUsage() == VertexFormatElement.Usage.POSITION) {
if (element.getType() == VertexFormatElement.Usage.POSITION) {
this.parent.put(e, this.transform(this.quadData[e][v]));
} else if (element.getUsage() == VertexFormatElement.Usage.NORMAL) {
} else if (element.getType() == VertexFormatElement.Usage.NORMAL) {
this.parent.put(e, this.transformNormal(this.quadData[e][v]));
} else {
this.parent.put(e, this.quadData[e][v]);
@@ -28,6 +28,7 @@ import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.item.Item;
@@ -73,7 +74,7 @@ public class DriveBakedModel extends DelegateBakedModel {
// cell-model being in slot 0,0 at the top left of the drive.
float xOffset = -col * 8 / 16.0f;
float yOffset = -row * 3 / 16.0f;
transform.setTranslation(xOffset, yOffset, 0);
transform.addToLastColumn(new Vector3f(xOffset, yOffset, 0));
int slot = row * 2 + col;
@@ -32,20 +32,20 @@ import javax.annotation.Nullable;
import com.google.common.base.Strings;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormatElement;
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.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.BlockView;
import net.minecraft.world.ILightReader;
import net.minecraftforge.client.model.data.IDynamicBakedModel;
import net.minecraftforge.client.model.data.ModelDataMap;
@@ -240,7 +240,7 @@ class GlassBakedModel implements IDynamicBakedModel {
VertexFormat vertexFormat = builder.getVertexFormat();
for (int e = 0; e < vertexFormat.getElements().size(); e++) {
VertexFormatElement el = vertexFormat.getElements().get(e);
switch (el.getUsage()) {
switch (el.getType()) {
case POSITION:
builder.put(e, (float) x, (float) y, (float) z, 1.0f);
break;
@@ -252,8 +252,8 @@ class GlassBakedModel implements IDynamicBakedModel {
break;
case UV:
if (el.getIndex() == 0) {
u = sprite.getInterpolatedU(u);
v = sprite.getInterpolatedV(v);
u = sprite.getFrameU(u);
v = sprite.getFrameV(v);
builder.put(e, u, v, 0f, 1f);
break;
}
@@ -305,8 +305,8 @@ class GlassBakedModel implements IDynamicBakedModel {
@Nonnull
@Override
public IModelData getModelData(@Nonnull ILightReader world, @Nonnull BlockPos pos, @Nonnull BlockState state,
@Nonnull IModelData tileData) {
public IModelData getModelData(@Nonnull BlockRenderView world, @Nonnull BlockPos pos, @Nonnull BlockState state,
@Nonnull IModelData tileData) {
EnumSet<Direction> flushWith = EnumSet.noneOf(Direction.class);
// Test every direction for another glass block
@@ -20,11 +20,11 @@ package appeng.client.render.model;
import java.util.List;
import net.minecraft.client.render.VertexFormatElement;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.util.math.Direction;
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
@@ -48,9 +48,9 @@ final class MatrixVertexTransformer extends QuadGatheringTransformer {
for (int v = 0; v < 4; v++) {
for (int e = 0; e < count; e++) {
VertexFormatElement element = elements.get(e);
if (element.getUsage() == VertexFormatElement.Usage.POSITION) {
if (element.getType() == VertexFormatElement.Usage.POSITION) {
this.parent.put(e, this.transform(this.quadData[e][v], element.getElementCount()));
} else if (element.getUsage() == VertexFormatElement.Usage.NORMAL) {
} else if (element.getType() == VertexFormatElement.Usage.NORMAL) {
this.parent.put(e, this.transformNormal(this.quadData[e][v]));
} else {
this.parent.put(e, this.quadData[e][v]);
@@ -61,7 +61,7 @@ public class CrankTESR extends BlockEntityRenderer<CrankBlockEntity> {
BlockState blockState = te.getCachedState();
BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
BakedModel model = dispatcher.getModelForState(blockState);
BakedModel model = dispatcher.getModel(blockState);
VertexConsumer buffer = buffers.getBuffer(TexturedRenderLayers.getEntityTranslucentCull());
dispatcher.getModelRenderer().renderModelBrightnessColor(ms.peek(), buffer, null, model, 1, 1, 1,
combinedLightIn, combinedOverlayIn);
@@ -4,17 +4,16 @@ import java.util.EnumMap;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
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.util.math.MatrixStack;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.renderer.RenderState;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -70,7 +69,7 @@ public class DriveLedTileEntityRenderer extends BlockEntityRenderer<DriveBlockEn
// Bottom Face
R, B, FR, L, B, FR, L, B, BA, R, B, BA, };
private static final RenderLayer STATE = RenderLayer.makeType("ae_drive_leds", DefaultVertexFormats.POSITION_COLOR, 7,
private static final RenderLayer STATE = RenderLayer.makeType("ae_drive_leds", VertexFormats.POSITION_COLOR, 7,
32565, false, true, RenderLayer.State.getBuilder().build(false));
public DriveLedTileEntityRenderer(BlockEntityRenderDispatcher rendererDispatcherIn) {
@@ -90,9 +89,9 @@ public class DriveLedTileEntityRenderer extends BlockEntityRenderer<DriveBlockEn
FacingToRotation.get(drive.getForward(), drive.getUp()).push(ms);
ms.translate(-0.5, -0.5, -0.5);
RenderType rt = RenderType.makeType("ae_drive_leds", DefaultVertexFormats.POSITION_COLOR, 7, 32565, false, true,
RenderType rt = RenderType.makeType("ae_drive_leds", VertexFormats.POSITION_COLOR, 7, 32565, false, true,
RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY).build(false));
IVertexBuilder buffer = buffers.getBuffer(STATE);
VertexConsumer buffer = buffers.getBuffer(STATE);
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 2; col++) {
@@ -175,7 +175,7 @@ public final class InscriberTESR extends BlockEntityRenderer<InscriberBlockEntit
float z, double texU, double texV, int overlayUV, int lightmapUV, Direction front) {
vb.pos(ms.peek().getMatrix(), x, y, z);
vb.color(1.0f, 1.0f, 1.0f, 1.0f);
vb.tex(sprite.getInterpolatedU(texU), sprite.getInterpolatedV(texV));
vb.tex(sprite.getFrameU(texU), sprite.getFrameV(texV));
vb.overlay(overlayUV);
vb.lightmap(lightmapUV);
vb.normal(ms.peek().getNormal(), front.getOffsetX(), front.getOffsetY(), front.getOffsetZ());
@@ -66,7 +66,7 @@ public final class FacadeItemGroup extends ItemGroup {
for (final Block b : ForgeRegistries.BLOCKS) {
try {
final Item item = Item.getItemFromBlock(b);
final Item item = Item.fromBlock(b);
if (item == Items.AIR) {
continue;
}
@@ -107,7 +107,7 @@ public class BlockTransitionEffectPacket extends BasePacket {
EnergyParticleData data = new EnergyParticleData(false, direction);
for (int zz = 0; zz < 32; zz++) {
if (AppEng.proxy.shouldAddParticles(Platform.getRandom())) {
if (AppEng.instance().shouldAddParticles(Platform.getRandom())) {
// Distribute the spawn point across the entire block's area
double x = pos.getX() + Platform.getRandomFloat();
double y = pos.getY() + Platform.getRandomFloat();
@@ -140,7 +140,7 @@ public class BlockTransitionEffectPacket extends BasePacket {
volume = 1;
pitch = 1;
} else if (soundMode == SoundMode.BLOCK) {
BlockSoundGroup soundType = blockState.getSoundType();
BlockSoundGroup soundType = blockState.getSoundGroup();
soundEvent = soundType.getBreakSound();
volume = soundType.volume;
pitch = soundType.pitch;
@@ -82,7 +82,7 @@ public class ClickPacket extends BasePacket {
// API for when an item in hand was right-clicked, with no block context
public ClickPacket(Hand hand) {
this(BlockPos.ZERO, null, 0, 0, 0, hand);
this(BlockPos.ORIGIN, null, 0, 0, 0, hand);
}
private ClickPacket(final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ,
@@ -135,9 +135,9 @@ public class InventoryActionPacket extends BasePacket {
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
if (this.action == InventoryAction.UPDATE_HAND) {
if (this.slotItem == null) {
AppEng.proxy.getPlayers().get(0).inventory.setItemStack(ItemStack.EMPTY);
AppEng.instance().getPlayers().get(0).inventory.setItemStack(ItemStack.EMPTY);
} else {
AppEng.proxy.getPlayers().get(0).inventory.setItemStack(this.slotItem.createItemStack());
AppEng.instance().getPlayers().get(0).inventory.setItemStack(this.slotItem.createItemStack());
}
}
}
@@ -74,7 +74,7 @@ public class ItemTransitionEffectPacket extends BasePacket {
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
EnergyParticleData data = new EnergyParticleData(true, this.d);
for (int zz = 0; zz < 8; zz++) {
if (AppEng.proxy.shouldAddParticles(Platform.getRandom())) {
if (AppEng.instance().shouldAddParticles(Platform.getRandom())) {
// Distribute the spawn point around the item's position
double x = this.x + Platform.getRandomFloat() * 0.5 - 0.25;
double y = this.y + Platform.getRandomFloat() * 0.5 - 0.25;

Some files were not shown because too many files have changed in this diff Show More