Fix rift being invisible after breaking door

This commit is contained in:
Runemoro 2018-01-22 17:46:50 -05:00
parent f7193289f3
commit 932aa6857b
4 changed files with 33 additions and 21 deletions

View file

@ -6,8 +6,10 @@ import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -15,6 +17,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.ddutils.Location;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.shared.rifts.registry.RiftRegistry;
@ -135,10 +139,8 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
DimDoors.log.error("Rift tile entity was null when breaking block at " + new Location(world, pos) + ", please report this error.");
}
if (rift.isPlaceRiftOnBreak() || rift.isRegistered() && RiftRegistry.instance().getSources(new Location(rift.getWorld(), rift.getPos())).size() > 0 && !rift.isAlwaysDelete()) {
IBlockState oldState = world.getBlockState(rift.getPos());
world.setBlockState(rift.getPos(), ModBlocks.RIFT.getDefaultState(), 2);
//world.notifyBlockUpdate(rift.getPos(), oldState, ModBlocks.RIFT.getDefaultState(), 3);
world.markBlockRangeForRenderUpdate(rift.getPos(), rift.getPos());
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
// This isn't run when we change the block from within block break
TileEntityFloatingRift newRift = (TileEntityFloatingRift) world.getTileEntity(pos);
newRift.copyFrom(rift);
newRift.updateType();

View file

@ -1,15 +1,12 @@
package org.dimdev.dimdoors.shared.rifts;
import lombok.Getter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -19,8 +16,6 @@ import org.dimdev.ddutils.*;
import org.dimdev.ddutils.nbt.NBTUtils;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.pocketlib.VirtualLocation;
import org.dimdev.dimdoors.shared.blocks.BlockDimensionalDoor;
import org.dimdev.dimdoors.shared.blocks.BlockFloatingRift;
import org.dimdev.dimdoors.shared.rifts.registry.LinkProperties;
import org.dimdev.dimdoors.shared.rifts.registry.Rift;
import org.dimdev.dimdoors.shared.rifts.registry.RiftRegistry;
@ -91,18 +86,6 @@ import javax.annotation.Nonnull;
deserializeNBT(pkt.getNbtCompound());
}
// Tile entity properties
// Use vanilla behavior of refreshing only when block changes, not state (otherwise, opening the door would destroy the tile entity)
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
// newState is not accurate if we change the state during onBlockBreak
newSate = world.getBlockState(pos);
return oldState.getBlock() != newSate.getBlock() &&
!(oldState.getBlock() instanceof BlockDimensionalDoor
&& newSate.getBlock() instanceof BlockFloatingRift);
}
// Modification functions
public void setRotation(float yaw, float pitch) {
@ -241,6 +224,7 @@ import javax.annotation.Nonnull;
if (color == null && newColor != null || !color.equals(newColor)) {
color = newColor;
markDirty();
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 2);
}
}
}

View file

@ -1,5 +1,8 @@
package org.dimdev.dimdoors.shared.tileentities;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.dimdev.ddutils.nbt.NBTUtils;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.annotatednbt.NBTSerializable;
@ -79,6 +82,14 @@ import java.util.Random;
TeleportUtils.teleport(entity, new Location(world, pos.offset(orientation, tpOffset)), orientation.getHorizontalAngle(), 0);
}
// Use vanilla behavior of refreshing only when block changes, not state (otherwise, opening the door would destroy the tile entity)
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
// newState is not accurate if we change the state during onBlockBreak
newSate = world.getBlockState(pos);
return oldState.getBlock() != newSate.getBlock();
}
public RGBA getEntranceRenderColor(Random rand) { // TODO: custom color
float red, green, blue;
switch(world.provider.getDimension()) {
@ -100,4 +111,6 @@ import java.util.Random;
public boolean isFloating() {
return false;
}
}

View file

@ -1,9 +1,13 @@
package org.dimdev.dimdoors.shared.tileentities;
import lombok.Setter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.dimdev.ddutils.nbt.NBTUtils;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.annotatednbt.NBTSerializable;
import org.dimdev.dimdoors.shared.blocks.BlockFloatingRift;
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
import java.util.List;
import java.util.Random;
@ -104,6 +108,15 @@ import net.minecraft.util.math.AxisAlignedBB;
return false;
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
// newState is not accurate if we change the state during onBlockBreak
newSate = world.getBlockState(pos);
return oldState.getBlock() != newSate.getBlock() &&
!(world.getTileEntity(pos) instanceof TileEntityRift && // This is to prevent setBlockState clearing the tile entity right after we set it in breakBlock
newSate.getBlock() instanceof BlockFloatingRift);
}
@Override
public boolean shouldRenderInPass(int pass) {
return pass == 1;