Skip to content

Commit

Permalink
Fix tile entity replacement
Browse files Browse the repository at this point in the history
Close #35
  • Loading branch information
The-Fireplace committed May 28, 2022
1 parent eb8aa99 commit 2b771f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ allprojects {
targetCompatibility = 1.8
}

version = "2.3.2+1.12.2"
version = "2.3.3+1.12.2"
group= "dev.the-fireplace"
archivesBaseName = "WorldGen-Block-Replacer"

Expand Down
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixed error messages not appearing sometimes with invalid config crash
Replacement now adds and removes tile entities if needed
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.the_fireplace.wgblockreplacer.api.world.ChunkReplacementData;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -74,14 +75,25 @@ private static boolean replaceBlocksInStorage(World world, Chunk chunk, int conf
}
for (int storageY = 0; storageY < 16; storageY++) {
if (storage.get(storageX, storageY, storageZ).equals(fromState)) {
int worldX = chunk.getPos().getXStart() + storageX;
int worldY = storage.getYLocation() + storageY;
int worldZ = chunk.getPos().getZStart() + storageZ;
boolean withinConfiguredYRange = CONFIG.getMinYs()[configArrayIndex] <= worldY && worldY <= CONFIG.getMaxYs()[configArrayIndex];
int chanceMultiplier = CONFIG.getMultiplyChances()[configArrayIndex] ? worldY : 1;
double replacementChance = CONFIG.getReplaceChances()[configArrayIndex] * chanceMultiplier;
if (withinConfiguredYRange
&& rand.nextDouble() <= replacementChance
) {
storage.set(storageX, storageY, storageZ, toState);
BlockPos worldBlockPos = new BlockPos(worldX, worldY, worldZ);
world.removeTileEntity(worldBlockPos);
if (toState.getBlock().hasTileEntity(toState)) {
TileEntity tileEntity = toState.getBlock().createTileEntity(world, toState);
if (tileEntity != null) {
tileEntity.setPos(worldBlockPos);
world.addTileEntity(tileEntity);
}
}
if (!replaced) {
replaced = true;
}
Expand Down

0 comments on commit 2b771f8

Please sign in to comment.