Skip to content

Commit

Permalink
Remove dimension related code
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel BOUCHET committed Jul 25, 2016
1 parent f46509c commit 9c685b2
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 661 deletions.
4 changes: 0 additions & 4 deletions run/config/capsule.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ balancing {


compatibility {
# id of the capsule dimension (where blocks are sent inside the capsule).
# Change needed only if there is conflict with an other mod using the same id. This id is used for both the dimension and the dimensionType.
I:dimensionId=2
I:providerId=7

# Id used to register the Enchantment "Recall".
# This enchantment allow a dropped item to come back into the thrower inventory (if not full) when it collided something.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package capsule.dimension;
package capsule;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.WorldSavedData;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/capsule/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ public static void registerItemRenderers(String modid) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(CapsuleItemsRegistrer.capsule, CapsuleItem.STATE_ONE_USE_ACTIVATED,
new ModelResourceLocation(modid + ":capsule_one_use_activated", "inventory"));

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(CapsuleItemsRegistrer.creativeTP, 0,
new ModelResourceLocation(modid + ":capsule_CTP", "inventory"));

Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor() {
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
if (stack.getItem() instanceof CapsuleItem) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/capsule/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import capsule.blocks.CapsuleBlocksRegistrer;
import capsule.command.CapsuleCommand;
import capsule.dimension.CapsuleDimensionRegistrer;
import capsule.enchantments.Enchantments;
import capsule.items.CapsuleItemsRegistrer;
import capsule.network.LabelEditedMessageToServer;
Expand Down Expand Up @@ -40,9 +39,6 @@ public void preInit(FMLPreInitializationEvent event) {
// network stuff
simpleNetworkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("CapsuleChannel");
simpleNetworkWrapper.registerMessage(MessageHandlerOnServer.class, LabelEditedMessageToServer.class, LABEL_EDITED_ID, Side.SERVER);

// register dimension on both client and server
CapsuleDimensionRegistrer.registerDimension();
}

public void init(FMLInitializationEvent event) {
Expand Down
249 changes: 0 additions & 249 deletions src/main/java/capsule/Helpers.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
package capsule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.command.NumberInvalidException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;

public class Helpers {

Expand All @@ -32,245 +22,6 @@ public class Helpers {
static byte BLOCK_PREVENT_RERENDER = 4;


/**
*
* @param sourceWorld
* from world
* @param destWorld
* to world
* @param srcOriginPos
* from pos
* @param destOriginPos
* to pos
* @param size
* using a square having a size of "size" blocks
* @param overridable
* The blocks in this list can be lost to allow a merge
* @param keepSource
* copy only, don't remove blocks from sourceWorld and allow
* duplication.
* @param sourceIgnorePos
* This blocks won't be transfered from source
* @param outOccupiedDestPos
* This blocks were already present at destination beofre the
* merge
* @return
*/
public static boolean swapRegions(WorldServer sourceWorld, WorldServer destWorld, BlockPos srcOriginPos, BlockPos destOriginPos, int size,
List<Block> overridable, List<Block> excluded, boolean keepSource, Map<BlockPos, Block> sourceIgnorePos,
Map<BlockPos, Block> outOccupiedDestPos, List<String> outEntityBlocking) {

Block air = Blocks.AIR;
if (!isDestinationValid(sourceWorld, destWorld, srcOriginPos, destOriginPos, size, overridable, excluded, outOccupiedDestPos, outEntityBlocking)) {
return false;
}

boolean flagdoTileDrops = sourceWorld.getGameRules().getBoolean("doTileDrops");
sourceWorld.getGameRules().setOrCreateGameRule("doTileDrops", "false");

Map<BlockPos, IBlockState> transferedBlocks = new HashMap<BlockPos,IBlockState>();

// 1st copy from srcWorld
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
for (int z = 0; z < size; z++) {

BlockPos srcPos = srcOriginPos.add(x, y, z);

IBlockState srcState = sourceWorld.getBlockState(srcPos);

// don't copy excluded blocks
// if must copy
if (!excluded.contains(srcState.getBlock()) && (sourceIgnorePos == null || !(sourceIgnorePos.keySet().contains(srcPos) && sourceIgnorePos.get(srcPos).equals(srcState.getBlock())))) {

BlockPos destPos = destOriginPos.add(x, y, z);
IBlockState destState = destWorld.getBlockState(destPos);

// store the dest block if it's overridable
if (air.equals(destState.getBlock()) || overridable.contains(destState.getBlock())) {

// remember the final state the block should be
transferedBlocks.put(destPos, srcState);

} // end if dest is overridable

} // end if must copy
}
}
}

Map<BlockPos, IBlockState> postlist = new HashMap<BlockPos,IBlockState>();
Map<BlockPos, BlockPos> postlistSource = new HashMap<BlockPos,BlockPos>();

// 2 copy to dest world and remove src world
// mark everything for update
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
for (int z = 0; z < size; z++) {

BlockPos srcPos = srcOriginPos.add(x, y, z);
BlockPos destPos = destOriginPos.add(x, y, z);

if (transferedBlocks.containsKey(destPos)) {

// try move block
IBlockState destState = transferedBlocks.get(destPos);
setBlockState(destWorld, destPos, destState);

// in case the set didn't work, try again later
if (destState != destWorld.getBlockState(destPos)) {
postlist.put(destPos, destState);
postlistSource.put(destPos, srcPos);
continue;
}

transferBlock(sourceWorld, destWorld, keepSource, srcPos, destPos);

// destWorld.notifyNeighborsOfStateChange(destPos,
// destState.getBlock());
}
}
}
}

// finally copy blocks that could not by copied first pass
for (BlockPos destPos : postlist.keySet()) {
IBlockState destState = postlist.get(destPos);

// try move block again
setBlockState(destWorld, destPos, destState);
transferBlock(sourceWorld, destWorld, keepSource, postlistSource.get(destPos), destPos);
}

for (BlockPos destPos : transferedBlocks.keySet()) {
destWorld.notifyNeighborsOfStateChange(destPos, transferedBlocks.get(destPos).getBlock());
}



// attempt to TP armor stand. Not working for now : they don't land on the right position, and it's really CPU intensive
// List<EntityArmorStand> armorstands = sourceWorld.getEntitiesWithinAABB(
// EntityArmorStand.class,
// new AxisAlignedBB(
// srcOriginPos.getX(), srcOriginPos.getY(), srcOriginPos.getZ(),
// srcOriginPos.getX() + size + 1, srcOriginPos.getY() + size + 1, srcOriginPos.getZ() + size + 1
// )
// );
//
// for(EntityArmorStand armorstand : armorstands){
// BlockPos relativePos = armorstand.getPosition().add(-srcOriginPos.getX(), -srcOriginPos.getY(), -srcOriginPos.getZ());
// armorstand.changeDimension(destWorld.provider.getDimension());
// armorstand.setPositionAndUpdate(destOriginPos.getX() + relativePos.getX(), destOriginPos.getY() + relativePos.getY(), destOriginPos.getZ() + relativePos.getZ());
// }

sourceWorld.getGameRules().setOrCreateGameRule("doTileDrops", String.valueOf(flagdoTileDrops));

return true;

}

public static void setBlockState(WorldServer world, BlockPos pos, IBlockState newState){
Chunk chunk = world.getChunkFromBlockCoords(pos);
IBlockState oldState = world.getBlockState(pos);

ExtendedBlockStorage[] ea = chunk.getBlockStorageArray();
int i = pos.getX() & 15;
int j = pos.getY();
int k = pos.getZ() & 15;
ExtendedBlockStorage extendedblockstorage = ea[j >> 4];
if (extendedblockstorage == null)
{
extendedblockstorage = ea[j >> 4] = new ExtendedBlockStorage(j >> 4 << 4, !world.provider.getHasNoSky());
}
extendedblockstorage.set(i, j & 15, k, newState);

world.notifyBlockUpdate(pos, oldState, newState, BLOCK_SEND_TO_CLIENT);
world.updateBlockTick(pos, newState.getBlock(), 0, 0);
}

public static void transferBlock(WorldServer sourceWorld, WorldServer destWorld, boolean keepSource, BlockPos srcPos, BlockPos destPos) {
// check tileEntity
TileEntity srcTE = sourceWorld.getTileEntity(srcPos);
TileEntity destTE = destWorld.getTileEntity(destPos);

if (srcTE != null && destTE != null) {
NBTTagCompound nbt = new NBTTagCompound();
srcTE.setPos(destPos);
srcTE.setWorldObj(destWorld);
srcTE.writeToNBT(nbt);
destTE.readFromNBT(nbt);
}

if (!keepSource) {
sourceWorld.removeTileEntity(srcPos);
setBlockState(sourceWorld, srcPos, Blocks.AIR.getDefaultState());
sourceWorld.notifyNeighborsOfStateChange(srcPos, Blocks.AIR);
}
}

/**
* Check whether a merge can be done at the destination
*
* @param sourceWorld
* @param destWorld
* @param srcOriginPos
* @param destOriginPos
* @param size
* @param overridable
* @param outOccupiedPositions
* Output param, the positions occupied a destination that will
* have to be ignored on
* @return List<BlockPos> occupied but not blocking positions
*/
public static boolean isDestinationValid(WorldServer sourceWorld, WorldServer destWorld, BlockPos srcOriginPos, BlockPos destOriginPos, int size,
List<Block> overridable, List<Block> excluded, Map<BlockPos, Block> outOccupiedPositions, List<String> outEntityBlocking) {

IBlockState air = Blocks.AIR.getDefaultState();

for (int y = size - 1; y >= 0; y--) {
for (int x = 0; x < size; x++) {
for (int z = 0; z < size; z++) {

BlockPos srcPos = srcOriginPos.add(x, y, z);
Block srcState = sourceWorld.getBlockState(srcPos).getBlock();

BlockPos destPos = destOriginPos.add(x, y, z);
Block destState = destWorld.getBlockState(destPos).getBlock();

boolean destOccupied = (destState != air && !overridable.contains(destState));
if (destState != air && outOccupiedPositions != null) {
outOccupiedPositions.put(destPos, destState);
}

boolean srcOccupied = (srcState != air && !overridable.contains(srcState));
@SuppressWarnings("rawtypes")
List entities = destWorld.getEntitiesWithinAABB(
EntityLivingBase.class,
new AxisAlignedBB(destPos.getX(), destPos.getY(), destPos.getZ(), destPos.getX() +1, destPos.getY()+1, destPos.getZ()+1)
);

// if destination is occupied, and source is neither
// excluded from transportation, nor can't be overriden by
// destination, then the merge can't be done.
if ((entities.size() > 0 && srcOccupied) || (destOccupied && !excluded.contains(srcState) && !overridable.contains(srcState))) {
if(entities.size() > 0 && outEntityBlocking != null){
for(Object e : entities){
Entity entity = (Entity)e;
if(entity != null){
outEntityBlocking.add(entity.getName());
}
}

}
return false;
}
}
}
}

return true;
}

public static BlockPos findBottomBlock(EntityItem entityItem, List<Block> excludedBlocks) {
if (entityItem.getEntityWorld() == null)
return null;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/capsule/StructureSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;

import capsule.dimension.CapsuleSavedData;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -463,8 +462,7 @@ public static String getUniqueName(WorldServer playerWorld, String player) {
}

/**
* Get the Capsule saving tool that can allocate a new Capsule zone in the
* capsule dimension.
* Get the Capsule saving tool that remembers last caspule id.
*
* @param capsuleWorld
* @return
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/capsule/dimension/CapsuleBiomeGen.java

This file was deleted.

Loading

0 comments on commit 9c685b2

Please sign in to comment.