Under 100.

This commit is contained in:
Flanks255 2021-11-21 13:49:33 -06:00
parent 4273fdd0f5
commit b6406c7adc
3 changed files with 76 additions and 78 deletions

View file

@ -81,7 +81,7 @@ public class ActuallyAdditionsClient {
}
// TODO: [port] validate that this works
public void sendBreakPacket(BlockPos pos) {
public static void sendBreakPacket(BlockPos pos) {
ClientPlayNetHandler connection = Minecraft.getInstance().getConnection();
assert connection != null;
assert Minecraft.getInstance().hitResult != null;

View file

@ -13,19 +13,15 @@ package de.ellpeck.actuallyadditions.mod.util;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.particles.IParticleData;
@ -34,9 +30,6 @@ import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.fml.network.NetworkRegistry;
import org.lwjgl.opengl.GL11;
public final class AssetUtil {
@ -92,7 +85,7 @@ public final class AssetUtil {
@OnlyIn(Dist.CLIENT)
public static void renderItemWithoutScrewingWithColors(ItemStack stack) {
if (StackUtil.isValid(stack)) {
/* if (StackUtil.isValid(stack)) {
Minecraft mc = Minecraft.getInstance();
ItemRenderer renderer = mc.getItemRenderer();
TextureManager manager = mc.getTextureManager();
@ -112,12 +105,12 @@ public final class AssetUtil {
GlStateManager._disableBlend();
manager.bind(TextureMap.LOCATION_BLOCKS_TEXTURE);
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
}
}*/
}
@OnlyIn(Dist.CLIENT)
public static void renderStackToGui(ItemStack stack, int x, int y, float scale) {
GlStateManager._pushMatrix();
/* GlStateManager._pushMatrix();
GlStateManager._enableBlend();
GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.enableGUIStandardItemLighting();
@ -134,13 +127,13 @@ public final class AssetUtil {
mc.font.setUnicodeFlag(flagBefore);
RenderHelper.turnOff();
GlStateManager._popMatrix();
GlStateManager._popMatrix();*/
}
//Copied from Gui.class and changed
@OnlyIn(Dist.CLIENT)
public static void drawHorizontalGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, float zLevel) {
float f = (startColor >> 24 & 255) / 255.0F;
/* float f = (startColor >> 24 & 255) / 255.0F;
float f1 = (startColor >> 16 & 255) / 255.0F;
float f2 = (startColor >> 8 & 255) / 255.0F;
float f3 = (startColor & 255) / 255.0F;
@ -164,7 +157,7 @@ public final class AssetUtil {
GlStateManager._shadeModel(7424);
GlStateManager._disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.enableTexture2D();*/
}
// @OnlyIn(Dist.CLIENT)
@ -221,7 +214,7 @@ public final class AssetUtil {
data.putFloat("Size", size);
data.putInt("MaxAge", maxAge);
data.putFloat("Alpha", alpha);
PacketHandler.THE_NETWORK.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
//PacketHandler.THE_NETWORK.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96)); //TODO
}
}
@ -261,7 +254,7 @@ public final class AssetUtil {
GlStateManager._pushMatrix();
GlStateManager._disableLighting();
/* GlStateManager._disableLighting();
GlStateManager._enableBlend();
GlStateManager._blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
int func = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
@ -270,7 +263,7 @@ public final class AssetUtil {
GlStateManager.translate(firstX - TileEntityRendererDispatcher.staticPlayerX, firstY - TileEntityRendererDispatcher.staticPlayerY, firstZ - TileEntityRendererDispatcher.staticPlayerZ);
GlStateManager.rotate((float) (180 * yaw / Math.PI), 0, 1, 0);
GlStateManager.rotate((float) (180 * pitch / Math.PI), 0, 0, 1);
GlStateManager.rotate((float) rot, 1, 0, 0);
GlStateManager.rotate((float) rot, 1, 0, 0);*/
/*if(r != r2 || g != g2 || b != b2){
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
@ -318,8 +311,8 @@ public final class AssetUtil {
tessy.draw();
}
else{*/
GlStateManager.disableTexture2D();
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
//GlStateManager.disableTexture2D();
//render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
for (double i = 0; i < 4; i++) {
double width = beamWidth * (i / 4.0);
render.vertex(length, width, width).uv(0, 0).uv2(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
@ -344,11 +337,11 @@ public final class AssetUtil {
}
tessy.end();
GlStateManager.enableTexture2D();
//GlStateManager.enableTexture2D();
//}
GlStateManager._alphaFunc(func, ref);
GlStateManager._blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
//GlStateManager._alphaFunc(func, ref);
//GlStateManager._blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager._disableBlend();
GlStateManager._enableLighting();
GlStateManager._popMatrix();

View file

@ -18,32 +18,33 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
import java.util.List;
@ -75,7 +76,7 @@ public final class WorldUtil {
ItemStack extracted = StackUtil.getEmpty();
if (ActuallyAdditions.commonCapsLoaded) {
Object handler = extractWrapper.getSlotlessHandler();
/* Object handler = extractWrapper.getSlotlessHandler();
if (handler instanceof ISlotlessItemHandler) {
ISlotlessItemHandler slotless = (ISlotlessItemHandler) handler;
@ -93,11 +94,11 @@ public final class WorldUtil {
}
//Leave the possibility to fall back to vanilla when there is a filter
}
}
}*/
}
if (!StackUtil.isValid(extracted)) {
IItemHandler handler = extractWrapper.getNormalHandler();
/* IItemHandler handler = extractWrapper.getNormalHandler();
if (handler != null) {
for (int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++) {
if (filter == null || !filter.needsCheck() || filter.check(handler.getStackInSlot(i))) {
@ -108,7 +109,7 @@ public final class WorldUtil {
}
}
}
}
}*/
}
return extracted;
@ -117,32 +118,35 @@ public final class WorldUtil {
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
if (maxTransfer > 0) {
Direction opp = sideTo == null
? null
: sideTo.getOpposite();
IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo);
IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp);
if (handlerFrom != null && handlerTo != null) {
int drain = handlerFrom.extractEnergy(maxTransfer, true);
if (drain > 0) {
int filled = handlerTo.receiveEnergy(drain, false);
handlerFrom.extractEnergy(filled, false);
return;
}
}
? null
: sideTo.getOpposite();
LazyOptional<IEnergyStorage> handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo);
LazyOptional<IEnergyStorage> handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp);
handlerFrom.ifPresent((from) -> {
handlerTo.ifPresent((to) -> {
int drain = from.extractEnergy(maxTransfer, true);
if (drain > 0) {
int filled = to.receiveEnergy(drain, false);
to.extractEnergy(filled, false);
}
});
});
}
}
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
if (maxTransfer > 0) {
if (tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())) {
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
FluidStack drain = handlerFrom.drain(maxTransfer, false);
if (drain != null) {
int filled = handlerTo.fill(drain.copy(), true);
handlerFrom.drain(filled, true);
}
}
LazyOptional<IFluidHandler> optionalFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
LazyOptional<IFluidHandler> optionalTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
optionalFrom.ifPresent((from) -> {
optionalTo.ifPresent((to) -> {
FluidStack drain = from.drain(maxTransfer, IFluidHandler.FluidAction.SIMULATE);
if (!drain.isEmpty()) {
int filled = to.fill(drain.copy(), IFluidHandler.FluidAction.EXECUTE);
from.drain(filled, IFluidHandler.FluidAction.EXECUTE);
}
});
});
}
}
@ -165,11 +169,11 @@ public final class WorldUtil {
}
public static ItemStack useItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
if (world instanceof WorldServer && StackUtil.isValid(stack) && pos != null) {
if (world instanceof ServerWorld && StackUtil.isValid(stack) && pos != null) {
BlockPos offsetPos = pos.relative(side);
BlockState state = world.getBlockState(offsetPos);
Block block = state.getBlock();
boolean replaceable = block.canBeReplaced(world, offsetPos);
boolean replaceable = false; //= block.canBeReplaced(world, offsetPos); //TODO
//Redstone
if (replaceable && stack.getItem() == Items.REDSTONE) {
@ -178,28 +182,28 @@ public final class WorldUtil {
}
//Plants
if (replaceable && stack.getItem() instanceof IPlantable) {
/* if (replaceable && stack.getItem() instanceof IPlantable) { //TODO
if (((IPlantable) stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)) {
if (world.setBlock(offsetPos, ((IPlantable) stack.getItem()).getPlant(world, offsetPos), 2)) {
return StackUtil.shrink(stack, 1);
}
}
}
}*/
//Everything else
try {
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) world);
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerWorld) world);
if (fake.connection == null) {
fake.connection = new NetHandlerSpaghettiServer(fake);
}
ItemStack heldBefore = fake.getMainHandItem();
setHandItemWithoutAnnoyingSound(fake, Hand.MAIN_HAND, stack.copy());
fake.gameMode.processRightClickBlock(fake, world, fake.getMainHandItem(), Hand.MAIN_HAND, offsetPos, side.getOpposite(), 0.5F, 0.5F, 0.5F);
//fake.gameMode.useItemOn(fake, world, fake.getMainHandItem(), Hand.MAIN_HAND, offsetPos, side.getOpposite(), 0.5F, 0.5F, 0.5F); //TODO
ItemStack result = fake.getItemInHand(Hand.MAIN_HAND);
setHandItemWithoutAnnoyingSound(fake, Hand.MAIN_HAND, heldBefore);
return result;
} catch (Exception e) {
ActuallyAdditions.LOGGER.error("Something that places Blocks at " + offsetPos.getX() + ", " + offsetPos.getY() + ", " + offsetPos.getZ() + " in World " + world.provider.getDimension() + " threw an Exception! Don't let that happen again!", e);
ActuallyAdditions.LOGGER.error("Something that places Blocks at " + offsetPos.getX() + ", " + offsetPos.getY() + ", " + offsetPos.getZ() + " in World " + world.dimension() + " threw an Exception! Don't let that happen again!", e);
}
}
return stack;
@ -208,12 +212,10 @@ public final class WorldUtil {
public static boolean dropItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
BlockPos coords = pos.relative(side);
if (world.hasChunkAt(coords)) {
EntityItem item = new EntityItem(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
ItemEntity item = new ItemEntity(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
item.setDeltaMovement(0,0,0);
return world.spawnEntity(item);
return world.addFreshEntity(item);
}
return false;
}
@ -236,7 +238,7 @@ public final class WorldUtil {
}
public static Direction getDirectionByPistonRotation(BlockState state) {
return state.getValue(BlockDirectional.FACING);
return state.getValue(BlockStateProperties.FACING);
}
public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) {
@ -255,9 +257,9 @@ public final class WorldUtil {
private static RayTraceResult getMovingObjectPosWithReachDistance(World world, PlayerEntity player, double distance, boolean p1, boolean p2, boolean p3) {
float f = player.xRot;
float f1 = player.yRot;
double d0 = player.posX;
double d1 = player.posY + player.getEyeHeight();
double d2 = player.posZ;
double d0 = player.position().x;
double d1 = player.position().y + player.getEyeHeight();
double d2 = player.position().z;
Vector3d vec3 = new Vector3d(d0, d1, d2);
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
@ -266,7 +268,9 @@ public final class WorldUtil {
float f6 = f3 * f4;
float f7 = f2 * f4;
Vector3d vec31 = vec3.add(f6 * distance, f5 * distance, f7 * distance);
return world.clipWithInteractionOverride(vec3, vec31, p1, p2, p3);
//return world.clipWithInteractionOverride(vec3, vec31, p1, p2, p3); //TODO
return new BlockRayTraceResult(Vector3d.ZERO, Direction.DOWN, BlockPos.ZERO, false);
}
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player) {
@ -274,7 +278,8 @@ public final class WorldUtil {
}
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(PlayerEntity.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
return new BlockRayTraceResult(Vector3d.ZERO, Direction.DOWN, BlockPos.ZERO, false); //TODO
//return getMovingObjectPosWithReachDistance(world, player, player.getAttribute(PlayerEntity.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
}
public static void setHandItemWithoutAnnoyingSound(PlayerEntity player, Hand hand, ItemStack stack) {
@ -295,7 +300,7 @@ public final class WorldUtil {
BreakEvent event = new BreakEvent(world, pos, state, fake);
if (!MinecraftForge.EVENT_BUS.post(event)) {
return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake);
//return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); //TODO what?!
}
}
return 0F;
@ -315,13 +320,13 @@ public final class WorldUtil {
Block block = state.getBlock();
if (player.isCreative()) {
if (block.removedByPlayer(state, world, pos, player, false)) {
if (block.removedByPlayer(state, world, pos, player, false, state.getFluidState())) {
block.destroy(world, pos, state);
}
// send update to client
if (!world.isClientSide) {
((ServerPlayerEntity) player).connection.send(new SPacketBlockChange(world, pos));
//((ServerPlayerEntity) player).connection.send(new SPacketBlockChange(world, pos)); //TODO dunno what this is
}
return true;
}
@ -338,14 +343,14 @@ public final class WorldUtil {
}
TileEntity tileEntity = world.getBlockEntity(pos);
if (block.removedByPlayer(state, world, pos, player, true)) { // boolean is if block can be harvested, checked above
if (block.removedByPlayer(state, world, pos, player, true, state.getFluidState())) { // boolean is if block can be harvested, checked above
block.destroy(world, pos, state);
block.playerDestroy(world, player, pos, state, tileEntity, stack);
block.popExperience(world, pos, xp);
block.popExperience(((ServerWorld) world), pos, xp);
}
// always send block update to client
((ServerPlayerEntity) player).connection.send(new SPacketBlockChange(world, pos));
//((ServerPlayerEntity) player).connection.send(new SPacketBlockChange(world, pos)); //TODO how
return true;
}
// client sided handling
@ -355,7 +360,7 @@ public final class WorldUtil {
// following code can be found in PlayerControllerMP.onPlayerDestroyBlock
world.levelEvent(2001, pos, Block.getId(state));
if (block.removedByPlayer(state, world, pos, player, true)) {
if (block.removedByPlayer(state, world, pos, player, true, state.getFluidState())) {
block.destroy(world, pos, state);
}
// callback to the tool