瀏覽代碼

fixes, fixes, fixes!

1.12
Adrian Siekierka 1 年之前
父節點
當前提交
909a71b0fc
共有 18 個檔案被更改,包括 328 行新增123 行删除
  1. 3
    2
      docs/changelog/0.5.5.txt
  2. 3
    0
      src/main/java/pl/asie/charset/lib/handlers/FluidExtraInformationHandler.java
  3. 42
    0
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartBaseCenter.java
  4. 3
    2
      src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartUtilsMultipart.java
  5. 1
    1
      src/main/java/pl/asie/charset/lib/utils/MultipartUtils.java
  6. 3
    0
      src/main/java/pl/asie/charset/lib/utils/Utils.java
  7. 8
    6
      src/main/java/pl/asie/charset/module/storage/chests/CustomCarryHandlerChest.java
  8. 10
    11
      src/main/java/pl/asie/charset/module/storage/chests/ItemBlockChestCharset.java
  9. 19
    0
      src/main/java/pl/asie/charset/module/storage/chests/PacketUpdatePlayerCount.java
  10. 25
    15
      src/main/java/pl/asie/charset/module/storage/chests/TileChestCharset.java
  11. 19
    0
      src/main/java/pl/asie/charset/module/storage/chests/modcompat/mcmultipart/MCMPAddonStorageChests.java
  12. 21
    11
      src/main/java/pl/asie/charset/module/storage/chests/modcompat/mcmultipart/MultipartChest.java
  13. 12
    15
      src/main/java/pl/asie/charset/module/storage/tanks/BlockTank.java
  14. 5
    1
      src/main/java/pl/asie/charset/module/storage/tanks/ItemBlockTank.java
  15. 71
    52
      src/main/java/pl/asie/charset/module/storage/tanks/TileTank.java
  16. 18
    7
      src/main/java/pl/asie/charset/module/storage/tanks/TileTankRenderer.java
  17. 34
    0
      src/main/java/pl/asie/charset/module/storage/tanks/modcompat/mcmultipart/MCMPAddonStorageTanks.java
  18. 31
    0
      src/main/java/pl/asie/charset/module/storage/tanks/modcompat/mcmultipart/MultipartTank.java

+ 3
- 2
docs/changelog/0.5.5.txt 查看文件

@@ -1,6 +1,7 @@
Additions:

* [storage.chests] MCMultiPart support!
* [storage.chests] MCMultiPart support
* [storage.tanks] Gaseous fluids now render as to encompass the entire tank
* Support for Forge's selective resource reloading

Bugs fixed:
@@ -9,4 +10,4 @@ Bugs fixed:
* [simplelogic.gates] [GitHub/#281] Freestanding Cables connecting to Gates
* [simplelogic.wires] [GitHub/#282] Weird behaviour with insulated cables and vanilla-esque redstone blocks
* [simplelogic.wires] [GitHub/#280] Missing render face on wire outer corners
* [tweak.carry] [GitHub/#277] Blacklist lilypads from carrying
* [tweak.carry] [GitHub/#277] Blacklist lilypads from carrying

+ 3
- 0
src/main/java/pl/asie/charset/lib/handlers/FluidExtraInformationHandler.java 查看文件

@@ -54,6 +54,9 @@ public class FluidExtraInformationHandler {
tooltip.add(TextFormatting.DARK_GRAY + "Density: " + stack.getFluid().getDensity(stack) + " kg/m^3");
tooltip.add(TextFormatting.DARK_GRAY + "Temperature: " + stack.getFluid().getTemperature(stack) + " K");
tooltip.add(TextFormatting.DARK_GRAY + "Viscosity: " + stack.getFluid().getViscosity(stack) + " m/s^2 (x10^-3)");
if (stack.getFluid().isGaseous(stack)) {
tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + "Gaseous");
}
}
}
}

+ 42
- 0
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartBaseCenter.java 查看文件

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.lib.modcompat.mcmultipart;

import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class MultipartBaseCenter extends MultipartBase {
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return EnumCenterSlot.CENTER;
}

@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return EnumCenterSlot.CENTER;
}
}

+ 3
- 2
src/main/java/pl/asie/charset/lib/modcompat/mcmultipart/MultipartUtilsMultipart.java 查看文件

@@ -37,6 +37,7 @@ import pl.asie.charset.lib.utils.MultipartUtils;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -67,8 +68,8 @@ public class MultipartUtilsMultipart extends MultipartUtils {
@Override
public Stream<TileEntity> getTileEntityPart(IBlockAccess world, BlockPos pos, Predicate<TileEntity> predicate) {
Optional<IMultipartContainer> container = MultipartHelper.getContainer(world, pos);
if (container.isPresent()) {
return container.get().getParts().values().stream().map((i) -> i.getTile().getTileEntity()).filter(predicate);
if (container.isPresent() && container.get().getParts().size() > 0) {
return container.get().getParts().values().stream().map((i) -> i.getTile().getTileEntity()).filter(Objects::nonNull).filter(predicate);
} else {
return super.getTileEntityPart(world, pos, predicate);
}

+ 1
- 1
src/main/java/pl/asie/charset/lib/utils/MultipartUtils.java 查看文件

@@ -87,7 +87,7 @@ public class MultipartUtils {

public Stream<TileEntity> getTileEntityPart(IBlockAccess world, BlockPos pos, Predicate<TileEntity> predicate) {
TileEntity tile = world.getTileEntity(pos);
if (predicate.test(tile)) {
if (tile != null && predicate.test(tile)) {
return Stream.of(tile);
} else {
return Stream.empty();

+ 3
- 0
src/main/java/pl/asie/charset/lib/utils/Utils.java 查看文件

@@ -21,6 +21,7 @@ package pl.asie.charset.lib.utils;

import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
@@ -29,6 +30,8 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

public final class Utils {
public static final AxisAlignedBB DUMMY_BB = new AxisAlignedBB(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);

private static final MethodHandle EXPLOSION_SIZE_GETTER;

static {

+ 8
- 6
src/main/java/pl/asie/charset/module/storage/chests/CustomCarryHandlerChest.java 查看文件

@@ -28,6 +28,9 @@ import net.minecraft.world.World;
import pl.asie.charset.api.carry.CustomCarryHandler;
import pl.asie.charset.api.carry.ICarryHandler;
import pl.asie.charset.lib.Properties;
import pl.asie.charset.lib.utils.MultipartUtils;

import java.util.Optional;

public class CustomCarryHandlerChest extends CustomCarryHandler {
public CustomCarryHandlerChest(ICarryHandler handler) {
@@ -57,16 +60,15 @@ public class CustomCarryHandlerChest extends CustomCarryHandler {

if (side.getAxis() != EnumFacing.Axis.Y) {
BlockPos otherPos = pos.offset(side.getOpposite());
TileEntity otherTile = world.getTileEntity(otherPos);
if (otherTile instanceof TileChestCharset
&& ((TileChestCharset) otherTile).material.getMaterial() == chest.material.getMaterial()) {
if (((TileChestCharset) otherTile).hasNeighbor()) {
Optional<TileChestCharset> otherTile = MultipartUtils.INSTANCE.getSingleTileEntity(world, otherPos, TileChestCharset.class);
if (otherTile.isPresent() && otherTile.get().material.getMaterial() == chest.material.getMaterial() && otherTile.get().isSideOpen(side)) {
if (otherTile.get().hasNeighbor()) {
return;
}

neighborPos = otherPos;
neighborFacing = side.getOpposite();
neighbor = (TileChestCharset) otherTile;
neighbor = otherTile.get();
}
}

@@ -78,7 +80,7 @@ public class CustomCarryHandlerChest extends CustomCarryHandler {
selfFacing = selfFacing.rotateY();
}

world.setBlockState(neighborPos, world.getBlockState(neighborPos).withProperty(Properties.FACING4, selfFacing), 2);
neighbor.getWorld().setBlockState(neighborPos, neighbor.getWorld().getBlockState(neighborPos).withProperty(Properties.FACING4, selfFacing), 2);
newState = newState.withProperty(Properties.FACING4, selfFacing);
world.setBlockState(pos, newState, 2);


+ 10
- 11
src/main/java/pl/asie/charset/module/storage/chests/ItemBlockChestCharset.java 查看文件

@@ -31,6 +31,7 @@ import net.minecraft.world.World;
import pl.asie.charset.lib.Properties;
import pl.asie.charset.lib.item.*;
import pl.asie.charset.lib.material.ItemMaterialRegistry;
import pl.asie.charset.lib.utils.MultipartUtils;

import java.util.Optional;

@@ -65,28 +66,26 @@ public class ItemBlockChestCharset extends ItemBlockBase {
if (player.isSneaking()) {
if (side.getAxis() != EnumFacing.Axis.Y) {
BlockPos otherPos = pos.offset(side.getOpposite());
TileEntity otherTile = world.getTileEntity(otherPos);
if (otherTile instanceof TileChestCharset
&& ((TileChestCharset) otherTile).material.getMaterial() == chest.material.getMaterial()) {
if (((TileChestCharset) otherTile).hasNeighbor()) {
Optional<TileChestCharset> otherTile = MultipartUtils.INSTANCE.getSingleTileEntity(world, otherPos, TileChestCharset.class);
if (otherTile.isPresent() && otherTile.get().material.getMaterial() == chest.material.getMaterial() && otherTile.get().isSideOpen(side)) {
if (otherTile.get().hasNeighbor()) {
return false;
}

neighborPos = otherPos;
neighborFacing = side.getOpposite();
neighbor = (TileChestCharset) otherTile;
neighbor = otherTile.get();
}
}
} else {
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
BlockPos otherPos = pos.offset(facing);
TileEntity otherTile = world.getTileEntity(otherPos);
if (otherTile instanceof TileChestCharset
&& ((TileChestCharset) otherTile).material.getMaterial() == chest.material.getMaterial()) {
if (neighborPos == null && !((TileChestCharset) otherTile).hasNeighbor()) {
Optional<TileChestCharset> otherTile = MultipartUtils.INSTANCE.getSingleTileEntity(world, otherPos, TileChestCharset.class);
if (otherTile.isPresent() && otherTile.get().material.getMaterial() == chest.material.getMaterial() && otherTile.get().isSideOpen(facing.getOpposite())) {
if (neighborPos == null && !otherTile.get().hasNeighbor()) {
neighborPos = otherPos;
neighborFacing = facing;
neighbor = (TileChestCharset) otherTile;
neighbor = otherTile.get();
}
}
}
@@ -99,7 +98,7 @@ public class ItemBlockChestCharset extends ItemBlockBase {
selfFacing = selfFacing.rotateY();
}

world.setBlockState(neighborPos, world.getBlockState(neighborPos).withProperty(Properties.FACING4, selfFacing), 2);
neighbor.getWorld().setBlockState(neighborPos, neighbor.getWorld().getBlockState(neighborPos).withProperty(Properties.FACING4, selfFacing), 2);
newState = newState.withProperty(Properties.FACING4, selfFacing);
}


+ 19
- 0
src/main/java/pl/asie/charset/module/storage/chests/PacketUpdatePlayerCount.java 查看文件

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.module.storage.chests;

import net.minecraft.network.INetHandler;

+ 25
- 15
src/main/java/pl/asie/charset/module/storage/chests/TileChestCharset.java 查看文件

@@ -47,6 +47,7 @@ import net.minecraftforge.items.ItemStackHandler;
import pl.asie.charset.ModCharset;
import pl.asie.charset.api.lib.IDebuggable;
import pl.asie.charset.api.lib.IMultiblockStructure;
import pl.asie.charset.lib.Properties;
import pl.asie.charset.lib.block.TileBase;
import pl.asie.charset.lib.block.TraitLockable;
import pl.asie.charset.lib.block.TraitMaterial;
@@ -58,12 +59,14 @@ import pl.asie.charset.lib.inventory.IContainerHandler;
import pl.asie.charset.lib.utils.MathUtils;
import pl.asie.charset.lib.utils.MultipartUtils;
import pl.asie.charset.lib.utils.redstone.RedstoneUtils;
import pl.asie.charset.module.storage.tanks.TileTank;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

public class TileChestCharset extends TileBase implements IContainerHandler, IItemHandlerModifiable, IMultiblockStructure, IDebuggable, ITickable {
protected TraitMaterial material;
@@ -110,9 +113,9 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt

//noinspection ConstantConditions
if (world != null && pos != null) {
TileEntity tile = world.getTileEntity(pos.offset(neighborFace));
if (tile instanceof TileChestCharset && !tile.isInvalid()) {
setNeighbor((TileChestCharset) tile, neighborFace);
Optional<TileChestCharset> tile = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.offset(neighborFace), TileChestCharset.class);
if (tile.isPresent() && !tile.get().isInvalid()) {
setNeighbor(tile.get(), neighborFace);
} else {
setNeighbor(null, null);
}
@@ -120,9 +123,9 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt
} else {
//noinspection ConstantConditions
if (world != null && pos != null) {
TileEntity tile = world.getTileEntity(pos.offset(neighborFace));
if (tile instanceof TileChestCharset && !tile.isInvalid()) {
neighbor = (TileChestCharset) tile;
Optional<TileChestCharset> tile = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.offset(neighborFace), TileChestCharset.class);
if (tile.isPresent() && !tile.get().isInvalid()) {
neighbor = tile.get();
}
}
}
@@ -202,7 +205,7 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return facing == EnumFacing.DOWN || facing == null || !MultipartUtils.INSTANCE.isSelfSideSolid(world, pos, facing);
return isSideOpen(facing);
}

if (capability == Capabilities.MULTIBLOCK_STRUCTURE || capability == Capabilities.DEBUGGABLE) {
@@ -233,7 +236,7 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt
// self position check
if (MultipartUtils.INSTANCE.intersects(
Collections.singleton(
new AxisAlignedBB(0, 0.875, 0, 1, 1, 1)
new AxisAlignedBB(0.0625, 0.875, 0.0625, 0.9375, 1, 0.9375)
), world, pos, (s) -> !(s.getBlock() instanceof BlockChestCharset)
)) {
return true;
@@ -262,13 +265,16 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt
boolean attached = false;

BlockPos otherPos = pos.offset(side);
TileEntity otherTile = world.getTileEntity(otherPos);
if (otherTile instanceof TileChestCharset
&& ((TileChestCharset) otherTile).material.getMaterial() == material.getMaterial()) {
if (!((TileChestCharset) otherTile).hasNeighbor()) {
attached = true;
setNeighbor((TileChestCharset) otherTile, side);
player.swingArm(hand);
TileChestCharset otherTile = MultipartUtils.INSTANCE.getSingleTileEntity(world, otherPos, TileChestCharset.class).orElse(null);
if (otherTile != null && otherTile.material.getMaterial() == material.getMaterial()) {
IBlockState myState = world.getBlockState(pos);
IBlockState otherState = otherTile.world.getBlockState(otherPos);
if (myState.getValue(Properties.FACING4) == otherState.getValue(Properties.FACING4)) {
if (!otherTile.hasNeighbor()) {
attached = true;
setNeighbor(otherTile, side);
player.swingArm(hand);
}
}
}

@@ -499,4 +505,8 @@ public class TileChestCharset extends TileBase implements IContainerHandler, IIt
public void setPlayerCountClient(int playerCount) {
this.playerCountClient = playerCount;
}

public boolean isSideOpen(EnumFacing facing) {
return facing == EnumFacing.DOWN || facing == null || !MultipartUtils.INSTANCE.isSelfSideSolid(world, pos, facing);
}
}

+ 19
- 0
src/main/java/pl/asie/charset/module/storage/chests/modcompat/mcmultipart/MCMPAddonStorageChests.java 查看文件

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.module.storage.chests.modcompat.mcmultipart;

import pl.asie.charset.lib.modcompat.mcmultipart.CharsetMCMPAddon;

+ 21
- 11
src/main/java/pl/asie/charset/module/storage/chests/modcompat/mcmultipart/MultipartChest.java 查看文件

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.module.storage.chests.modcompat.mcmultipart;

import mcmultipart.api.multipart.IMultipart;
@@ -11,8 +30,9 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import pl.asie.charset.lib.modcompat.mcmultipart.MultipartBase;
import pl.asie.charset.lib.modcompat.mcmultipart.MultipartBaseCenter;

public class MultipartChest extends MultipartBase {
public class MultipartChest extends MultipartBaseCenter {
private final Block block;

public MultipartChest(Block block) {
@@ -23,14 +43,4 @@ public class MultipartChest extends MultipartBase {
public Block getBlock() {
return block;
}

@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return EnumCenterSlot.CENTER;
}

@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return EnumCenterSlot.CENTER;
}
}

+ 12
- 15
src/main/java/pl/asie/charset/module/storage/tanks/BlockTank.java 查看文件

@@ -53,11 +53,14 @@ import pl.asie.charset.lib.notify.component.NotificationComponentFluidStack;
import pl.asie.charset.lib.notify.component.NotificationComponentString;
import pl.asie.charset.lib.utils.FluidUtils;
import pl.asie.charset.lib.utils.ItemUtils;
import pl.asie.charset.lib.utils.MultipartUtils;
import pl.asie.charset.lib.utils.SoundUtils;

import java.util.Optional;

public class BlockTank extends BlockBase implements ITileEntityProvider {
public static final int VARIANTS = 18;
protected static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.05f, 0, 0.05f, 0.95f, 1, 0.95f);
protected static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.0625f, 0, 0.0625f, 0.9375f, 1, 0.9375f);
protected static final PropertyInteger VARIANT = PropertyInteger.create("connections", 0, 11);

public BlockTank() {
@@ -72,17 +75,7 @@ public class BlockTank extends BlockBase implements ITileEntityProvider {
}

protected int getVariant(IBlockAccess access, BlockPos pos) {
IBlockState state = access.getBlockState(pos);
if (!(state.getBlock() instanceof BlockTank)) {
return -1;
}

TileEntity tile = access.getTileEntity(pos);
if (tile instanceof TileTank) {
return ((TileTank) tile).getVariant();
} else {
return 0;
}
return MultipartUtils.INSTANCE.getSingleTileEntity(access, pos, TileTank.class).map(TileTank::getVariant).orElse(-1);
}

@Override
@@ -137,6 +130,8 @@ public class BlockTank extends BlockBase implements ITileEntityProvider {
int variantUp = getVariant(worldIn, pos.up());
int variantDown = getVariant(worldIn, pos.down());

System.out.println(pos + " " + variant + " " + variantUp + " " + variantDown);

return state.withProperty(VARIANT,
((variantUp == variant) ? 0 : 2)
| ((variantDown == variant) ? 0 : 1)
@@ -261,15 +256,17 @@ public class BlockTank extends BlockBase implements ITileEntityProvider {
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
// Must not place an empty tank between two tanks which differ only in liquid
return !TileTank.checkPlacementConflict(worldIn.getTileEntity(pos.down()), worldIn.getTileEntity(pos.up()), -1);
return !TileTank.checkPlacementConflict(
MultipartUtils.INSTANCE.getSingleTileEntity(worldIn, pos.down(), TileTank.class).orElse(null),
MultipartUtils.INSTANCE.getSingleTileEntity(worldIn, pos.up(), TileTank.class).orElse(null),
-1);
}

@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
// Tank connection refresh logic
if (blockIn == this || worldIn.isAirBlock(fromPos)) {
BlockPos tankPos = pos;
TileEntity tankEntity = worldIn.getTileEntity(tankPos);
TileEntity tankEntity = worldIn.getTileEntity(pos);
if (tankEntity instanceof TileTank) {
((TileTank) tankEntity).onTankStructureChanged();
}

+ 5
- 1
src/main/java/pl/asie/charset/module/storage/tanks/ItemBlockTank.java 查看文件

@@ -30,6 +30,7 @@ import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import pl.asie.charset.lib.item.ItemBlockBase;
import pl.asie.charset.lib.utils.ColorUtils;
import pl.asie.charset.lib.utils.MultipartUtils;

public class ItemBlockTank extends ItemBlockBase {
public ItemBlockTank(Block block) {
@@ -65,7 +66,10 @@ public class ItemBlockTank extends ItemBlockBase {

@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
if (TileTank.checkPlacementConflict(worldIn.getTileEntity(pos.down()), worldIn.getTileEntity(pos.up()), (stack.getTagCompound().getInteger("color") + 1) % BlockTank.VARIANTS)) {
if (TileTank.checkPlacementConflict(
MultipartUtils.INSTANCE.getSingleTileEntity(worldIn, pos.down(), TileTank.class).orElse(null),
MultipartUtils.INSTANCE.getSingleTileEntity(worldIn, pos.up(), TileTank.class).orElse(null),
(stack.getTagCompound().getInteger("color") + 1) % BlockTank.VARIANTS)) {
return false;
} else {
return super.placeBlockAt(stack, player, worldIn, pos, side, hitX, hitY, hitZ, newState);

+ 71
- 52
src/main/java/pl/asie/charset/module/storage/tanks/TileTank.java 查看文件

@@ -55,7 +55,10 @@ import pl.asie.charset.lib.misc.DoubleClickHandler;
import pl.asie.charset.lib.scheduler.Scheduler;
import pl.asie.charset.lib.utils.FluidUtils;
import pl.asie.charset.lib.utils.ItemUtils;
import pl.asie.charset.lib.utils.MultipartUtils;
import pl.asie.charset.lib.utils.Utils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;

@@ -100,13 +103,13 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma
}
}

public static boolean checkPlacementConflict(TileEntity a, TileEntity b, int variant) {
if (a instanceof TileTank && b instanceof TileTank
&& ((TileTank) a).getBottomTank().fluidStack != null
&& ((TileTank) b).getBottomTank().fluidStack != null
&& ((TileTank) a).variant == variant
&& ((TileTank) a).variant == ((TileTank) b).variant) {
return !((TileTank) a).getBottomTank().fluidStack.isFluidEqual(((TileTank) b).getBottomTank().fluidStack);
public static boolean checkPlacementConflict(TileTank a, TileTank b, int variant) {
if (a != null && b != null
&& a.getBottomTank().fluidStack != null
&& b.getBottomTank().fluidStack != null
&& a.variant == variant
&& a.variant == b.variant) {
return !a.getBottomTank().fluidStack.isFluidEqual(b.getBottomTank().fluidStack);
} else {
return false;
}
@@ -125,8 +128,8 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma

public boolean setVariant(int variant) {
if (variant >= 0 && variant < 17 && this.variant != variant) {
TileEntity tUp = world.getTileEntity(pos.up());
TileEntity tDown = world.getTileEntity(pos.down());
TileTank tUp = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.up(), TileTank.class).orElse(null);
TileTank tDown = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.down(), TileTank.class).orElse(null);
if (!(checkPlacementConflict(this, tUp, variant) || checkPlacementConflict(this, tDown, variant) || checkPlacementConflict(tUp, tDown, variant))) {
this.variant = variant;
markBlockForUpdate();
@@ -152,21 +155,21 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma
}

protected void onTankStructureChanged() {
updateAboveTank();
boolean changed = updateAboveTank();
BlockPos tankPos = getPos();
TileEntity tankEntity = this;
TileTank tankEntity = this;

while (tankEntity instanceof TileTank) {
((TileTank) tankEntity).findBottomTank();
while (tankEntity != null) {
changed |= tankEntity.findBottomTank();
tankPos = tankPos.up();
tankEntity = getWorld().getTileEntity(tankPos);
tankEntity = MultipartUtils.INSTANCE.getSingleTileEntity(world, tankPos, TileTank.class).orElse(null);
}

onStackModified();
BlockPos below = getPos().down();
TileEntity belowEntity = world.getTileEntity(below);
if (belowEntity instanceof TileTank) {
((TileTank) belowEntity).getBottomTank().onStackModified();
if (changed) {
onStackModified();
BlockPos below = getPos().down();
Optional<TileTank> belowEntity = MultipartUtils.INSTANCE.getSingleTileEntity(world, below, TileTank.class);
belowEntity.ifPresent((a) -> a.getBottomTank().onStackModified());
}
}

@@ -286,54 +289,66 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma
return tank.getVariant() == getVariant();
}

protected void updateAboveTank() {
TileEntity nTank = world.getTileEntity(pos.up());
if (nTank instanceof TileTank && connects((TileTank) nTank) && ((TileTank) nTank).connects(this)) {
aboveTank = (TileTank) nTank;
protected boolean updateAboveTank() {
TileTank oldAboveTank = aboveTank;
boolean changed = false;

TileTank nTank = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.up(), TileTank.class).orElse(null);
if (nTank != null && connects(nTank) && nTank.connects(this)) {
aboveTank = nTank;
if (isCreative() && fluidStack != null && aboveTank.fluidStack == null) {
aboveTank.fluidStack = fluidStack.copy();
aboveTank.updateAboveTank();
changed |= aboveTank.updateAboveTank();
}
} else {
aboveTank = null;
}

return changed || oldAboveTank != aboveTank;
}

protected void findBottomTank() {
protected boolean findBottomTank() {
TileTank tank = this;
Stack<TileTank> drainTanks = new Stack<TileTank>();
for (int y = pos.getY() - 1; y >= 0; y--) {
BlockPos nPos = new BlockPos(pos.getX(), y, pos.getZ());
TileEntity nTank = world.getTileEntity(nPos);
if (nTank instanceof TileTank && connects((TileTank) nTank) && ((TileTank) nTank).connects(this)) {
tank = (TileTank) nTank;
TileTank nTank = MultipartUtils.INSTANCE.getSingleTileEntity(world, nPos, TileTank.class).orElse(null);
if (nTank != null && connects(nTank) && nTank.connects(this)) {
tank = nTank;
drainTanks.add(tank);
} else {
break;
}
}
bottomTank = tank;

// Shift the liquid down in case there's new tanks below
boolean fluidStackChanged = false;
while (!drainTanks.empty() && fluidStack != null && fluidStack.amount > 0) {
tank = drainTanks.pop();
if (bottomTank != tank) {
bottomTank = tank;

if (tank.fluidStack == null) {
tank.fluidStack = fluidStack;
fluidStack = null;
fluidStackChanged = true;
} else {
int toAdd = Math.min(TileTank.CAPACITY - tank.fluidStack.amount, fluidStack.amount);
tank.fluidStack.amount += toAdd;
fluidStack.amount -= toAdd;
if (fluidStack.amount == 0) fluidStack = null;
fluidStackChanged = true;
// Shift the liquid down in case there's new tanks below
boolean fluidStackChanged = false;
while (!drainTanks.empty() && fluidStack != null && fluidStack.amount > 0) {
tank = drainTanks.pop();

if (tank.fluidStack == null) {
tank.fluidStack = fluidStack;
fluidStack = null;
fluidStackChanged = true;
} else {
int toAdd = Math.min(TileTank.CAPACITY - tank.fluidStack.amount, fluidStack.amount);
tank.fluidStack.amount += toAdd;
fluidStack.amount -= toAdd;
if (fluidStack.amount == 0) fluidStack = null;
fluidStackChanged = true;
}

tank.onStackModified();
}
if (fluidStackChanged) onStackModified();

tank.onStackModified();
return true;
} else {
return false;
}
if (fluidStackChanged) onStackModified();
}

public Iterator<TileTank> getAllTanks() {
@@ -534,12 +549,10 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
return facing == null || facing.getAxis() == EnumFacing.Axis.Y || !MultipartUtils.INSTANCE.isSelfSideSolid(world, pos, facing);
} else if (capability == Capabilities.DEBUGGABLE) {
return true;
} else if (capability == Capabilities.MOVABLE) {
return true;
} else if (capability == Capabilities.MULTIBLOCK_STRUCTURE) {
} else if (capability == Capabilities.MOVABLE || capability == Capabilities.MULTIBLOCK_STRUCTURE) {
return true;
} else {
return super.hasCapability(capability, facing);
@@ -578,8 +591,8 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma

@Override
public boolean canMoveTo(World world, BlockPos pos) {
TileEntity tUp = world.getTileEntity(pos.up());
TileEntity tDown = world.getTileEntity(pos.down());
TileTank tUp = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.up(), TileTank.class).orElse(null);
TileTank tDown = MultipartUtils.INSTANCE.getSingleTileEntity(world, pos.down(), TileTank.class).orElse(null);
return !(checkPlacementConflict(this, tUp, variant) || checkPlacementConflict(this, tDown, variant) || checkPlacementConflict(tUp, tDown, variant));
}

@@ -606,16 +619,22 @@ public class TileTank extends TileBase implements FluidUtils.IFluidHandlerAutoma
return false;
}

public boolean isGaseous() {
TileTank bottomTank = getBottomTank();
return bottomTank.fluidStack != null && bottomTank.fluidStack.getFluid().isGaseous(bottomTank.fluidStack);
}

@Override
public boolean isCacheValid() {
return !isInvalid();
}

@Override
@Nonnull
public net.minecraft.util.math.AxisAlignedBB getRenderBoundingBox() {
TileTank bottomTank = getBottomTank();
if (bottomTank != this) {
return new AxisAlignedBB(getPos());
return Utils.DUMMY_BB;
} else {
BlockPos bottomPos = getBottomTank().getPos();
int height = getCapacity() / TileTank.CAPACITY;

+ 18
- 7
src/main/java/pl/asie/charset/module/storage/tanks/TileTankRenderer.java 查看文件

@@ -38,6 +38,7 @@ import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.util.vector.Vector3f;
import pl.asie.charset.lib.render.model.ModelTransformer;
import pl.asie.charset.lib.render.model.SimpleBakedModel;
import pl.asie.charset.lib.utils.MultipartUtils;
import pl.asie.charset.lib.utils.ProxiedBlockAccess;
import pl.asie.charset.lib.utils.RenderUtils;

@@ -48,9 +49,11 @@ public class TileTankRenderer extends FastTESR<TileTank> {

private static final class FluidColorTransformer implements ModelTransformer.IVertexTransformer {
private final int color;
private final float alpha;

public FluidColorTransformer(int color) {
public FluidColorTransformer(int color, float alpha) {
this.color = color;
this.alpha = alpha;
}

@Override
@@ -59,6 +62,7 @@ public class TileTankRenderer extends FastTESR<TileTank> {
for (int i = 0; i < Math.min(data.length, 4); i++) {
data[i] = data[i] * ((color >> ((i < 3 ? (2 - i) : i) * 8)) & 0xFF) / 255.0f;
}
data[3] *= alpha;
}
return data;
}
@@ -98,9 +102,15 @@ public class TileTankRenderer extends FastTESR<TileTank> {
SimpleBakedModel smodel = new SimpleBakedModel();

int color = contents.getFluid().getColor(contents);
boolean gaseous = tank.isGaseous();

Vector3f from = new Vector3f(1.025f, 0.025f, 1.025f);
Vector3f to = new Vector3f(14.975f, Math.min(16 * tankCount - 0.025f, height * 16), 14.975f);
float modelOffset = 0.025f;
float maxHeight = 16 * tankCount - modelOffset;
float modelHeight = gaseous ? maxHeight : Math.min(maxHeight, height * 16);
float alpha = gaseous ? ((height * 0.875f / tankCount) + 0.125f) : 1.0f;

Vector3f from = new Vector3f(1f + modelOffset, modelOffset, 1f + modelOffset);
Vector3f to = new Vector3f(15f - modelOffset, modelHeight, 15f - modelOffset);

smodel.addQuad(null, RenderUtils.createQuad(from, to, EnumFacing.DOWN, sprite, -1));
smodel.addQuad(null, RenderUtils.createQuad(from, to, EnumFacing.UP, sprite, -1));
@@ -114,10 +124,10 @@ public class TileTankRenderer extends FastTESR<TileTank> {
}
}

if (color == -1) {
if (color == -1 && alpha == 1.0F) {
model = smodel;
} else {
model = ModelTransformer.transform(smodel, state, 0L, new FluidColorTransformer(color));
model = ModelTransformer.transform(smodel, state, 0L, new FluidColorTransformer(color, alpha));
}

int light = contents.getFluid().getLuminosity();
@@ -131,8 +141,8 @@ public class TileTankRenderer extends FastTESR<TileTank> {
BlockPos pos = te.getPos();

if (te.getWorld() != null) {
TileEntity lowerTile = te.getWorld().getTileEntity(pos.down());
if (lowerTile instanceof TileTank && ((TileTank) lowerTile).connects(te) && te.connects((TileTank) lowerTile)) {
TileTank lowerTile = MultipartUtils.INSTANCE.getSingleTileEntity(getWorld(), pos.down(), TileTank.class).orElse(null);
if (lowerTile != null && lowerTile.connects(te) && te.connects(lowerTile)) {
return;
}
}
@@ -141,6 +151,7 @@ public class TileTankRenderer extends FastTESR<TileTank> {
// TODO: Hack - tank caching does not properly update on client
te.findBottomTank();
}

FluidStack contents = te.getContents();
int tankCount = te.getCapacity() / TileTank.CAPACITY;


+ 34
- 0
src/main/java/pl/asie/charset/module/storage/tanks/modcompat/mcmultipart/MCMPAddonStorageTanks.java 查看文件

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.module.storage.tanks.modcompat.mcmultipart;

import pl.asie.charset.lib.modcompat.mcmultipart.CharsetMCMPAddon;
import pl.asie.charset.lib.modcompat.mcmultipart.MCMPAddonBase;
import pl.asie.charset.module.storage.tanks.CharsetStorageTanks;
import pl.asie.charset.module.storage.tanks.TileTank;

//@CharsetMCMPAddon("storage.tanks")
public class MCMPAddonStorageTanks extends MCMPAddonBase {
public MCMPAddonStorageTanks() {
super(CharsetStorageTanks.tankBlock, CharsetStorageTanks.tankItem,
MultipartTank::new, (tile) -> tile instanceof TileTank);
}
}


+ 31
- 0
src/main/java/pl/asie/charset/module/storage/tanks/modcompat/mcmultipart/MultipartTank.java 查看文件

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset 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.
*
* Charset 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 Charset. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.charset.module.storage.tanks.modcompat.mcmultipart;

import net.minecraft.block.Block;
import pl.asie.charset.lib.modcompat.mcmultipart.MultipartBaseCenter;
import pl.asie.charset.module.storage.tanks.CharsetStorageTanks;

public class MultipartTank extends MultipartBaseCenter {
@Override
public Block getBlock() {
return CharsetStorageTanks.tankBlock;
}
}

Loading…
取消
儲存