Updated CustomNPCs & VariedCommodities compatibility to 1.12.2

This commit is contained in:
Unknown 2019-09-27 11:09:42 +02:00 committed by unknown
parent c14f2ebfc6
commit 0c30cda74a
3 changed files with 344 additions and 85 deletions

View file

@ -13,24 +13,25 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class CompatCustomNpcs implements IBlockTransformer {
public class CompatCustomNPCs implements IBlockTransformer {
private static Class<?> classBlockBlood;
// CustomNPCs
private static Class<?> classBlockBorder;
private static Class<?> classBlockCarpentryBench;
private static Class<?> classBlockBuilder;
private static Class<?> classBlockMailbox;
private static Class<?> classTileColorable;
private static Class<?> classTileBigSign;
private static Class<?> classBlockNpcRedstone;
public static void register() {
try {
classBlockBlood = Class.forName("noppes.npcs.blocks.BlockBlood");
classBlockBorder = Class.forName("noppes.npcs.blocks.BlockBorder");
// customNPC
classBlockBorder = Class.forName("noppes.npcs.blocks.BlockBorder");
classBlockBuilder = Class.forName("noppes.npcs.blocks.BlockBuilder");
classBlockCarpentryBench = Class.forName("noppes.npcs.blocks.BlockCarpentryBench");
classBlockMailbox = Class.forName("noppes.npcs.blocks.BlockMailbox");
classTileColorable = Class.forName("noppes.npcs.blocks.tiles.TileColorable");
classTileBigSign = Class.forName("noppes.npcs.blocks.tiles.TileBigSign");
WarpDriveConfig.registerBlockTransformer("CustomNpcs", new CompatCustomNpcs());
classBlockNpcRedstone = Class.forName("noppes.npcs.blocks.BlockNpcRedstone");
WarpDriveConfig.registerBlockTransformer("CustomNPCs", new CompatCustomNPCs());
} catch(final ClassNotFoundException exception) {
exception.printStackTrace();
}
@ -38,12 +39,11 @@ public class CompatCustomNpcs implements IBlockTransformer {
@Override
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
return classBlockBlood.isInstance(block)
|| classBlockBorder.isInstance(block)
return classBlockBorder.isInstance(block)
|| classBlockBuilder.isInstance(block)
|| classBlockCarpentryBench.isInstance(block)
|| classBlockMailbox.isInstance(block)
|| classTileColorable.isInstance(tileEntity)
|| classTileBigSign.isInstance(tileEntity);
|| classBlockNpcRedstone.isInstance(block);
}
@Override
@ -63,21 +63,36 @@ public class CompatCustomNpcs implements IBlockTransformer {
// nothing to do
}
// Transformation handling required:
// metadata
// noppes.npcs.blocks.BlockBlood Blood 0 1 2 3
// noppes.npcs.blocks.BlockCarpentryBench Anvil 0 1 2 3 4 5 6 7
// noppes.npcs.blocks.BlockMailbox Mailbox 0 1 2 3 4 5 6 7
//
// NBT tags
// noppes.npcs.blocks.BlockBorder BorderRotation (integer) 0 1 2 3
// noppes.npcs.blocks.tiles.TileColorable BannerRotation (integer) 0 1 2 3 mostly, but not limited to noppes.npcs.blocks.BlockRotated
// noppes.npcs.blocks.tiles.TileBigSign SignRotation (integer) 0 1 2 3
// Transformation handling required as of CustomNPCs_1.12.2(30Jan19):
// noppes.npcs.blocks.BlockInterface
// noppes.npcs.blocks.BlockBorder
// meta ROTATION 0 1 2 3
// int BorderRotation 0 1 2 3
// noppes.npcs.blocks.BlockBuilder
// meta ROTATION 0 1 2 3
// int Rotation (relative to block => ignore it?)
// noppes.npcs.blocks.BlockCarpentryBench
// meta ROTATION 0 1 2 3
// noppes.npcs.blocks.BlockCopy
// meta -none-
// noppes.npcs.blocks.BlockMailbox
// meta ROTATION 0 1 2 3 | TYPE 0 4 8
// noppes.npcs.BlockNpcRedstone
// meta -none-
// int BlockOnRangeX/BlockOnRangeZ
// int BlockOffRangeX/BlockOffRangeZ
// noppes.npcs.blocks.BlockWaypoint
// meta -none-
// BlockDoor
// noppes.npcs.blocks.BlockNpcDoorInterface
// noppes.npcs.blocks.BlockScriptedDoor
// meta (same as vanilla)
// ----------------------------------------- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] mrot4 = { 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] mrot8 = { 1, 2, 3, 0, 5, 6, 7, 4, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] mrotMailbox = { 1, 2, 3, 0, 5, 6, 7, 4, 9, 10, 11, 8, 12, 13, 14, 15 };
@Override
public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) {
@ -86,7 +101,48 @@ public class CompatCustomNpcs implements IBlockTransformer {
return metadata;
}
if (classBlockBlood.isInstance(block)) {
if ( nbtTileEntity != null
&& nbtTileEntity.hasKey("BorderRotation") ) {
final int BorderRotation = nbtTileEntity.getInteger("BorderRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("BorderRotation", mrot4[BorderRotation]);
break;
case 2:
nbtTileEntity.setInteger("BorderRotation", mrot4[mrot4[BorderRotation]]);
break;
case 3:
nbtTileEntity.setInteger("BorderRotation", mrot4[mrot4[mrot4[BorderRotation]]]);
break;
default:
break;
}
}
if ( nbtTileEntity != null
&& nbtTileEntity.hasKey("BlockOnRangeX") ) {
final int BlockOnRangeX = nbtTileEntity.getInteger("BlockOnRangeX");
final int BlockOnRangeZ = nbtTileEntity.getInteger("BlockOnRangeZ");
final int BlockOffRangeX = nbtTileEntity.getInteger("BlockOffRangeX");
final int BlockOffRangeZ = nbtTileEntity.getInteger("BlockOffRangeZ");
switch (rotationSteps) {
case 1:
case 3:
nbtTileEntity.setInteger("BlockOnRangeX", BlockOnRangeZ);
nbtTileEntity.setInteger("BlockOnRangeZ", BlockOnRangeX);
nbtTileEntity.setInteger("BlockOffRangeX", BlockOffRangeZ);
nbtTileEntity.setInteger("BlockOffRangeZ", BlockOffRangeX);
break;
default:
break;
}
}
if ( classBlockBorder.isInstance(block)
|| classBlockBuilder.isInstance(block)
|| classBlockCarpentryBench.isInstance(block) ) {
switch (rotationSteps) {
case 1:
return mrot4[metadata];
@ -98,66 +154,14 @@ public class CompatCustomNpcs implements IBlockTransformer {
return metadata;
}
}
if ( classBlockCarpentryBench.isInstance(block)
|| classBlockMailbox.isInstance(block) ) {
if (classBlockMailbox.isInstance(block)) {
switch (rotationSteps) {
case 1:
return mrot8[metadata];
return mrotMailbox[metadata];
case 2:
return mrot8[mrot8[metadata]];
return mrotMailbox[mrotMailbox[metadata]];
case 3:
return mrot8[mrot8[mrot8[metadata]]];
default:
return metadata;
}
}
if (nbtTileEntity.hasKey("BannerRotation")) {
final int BannerRotation = nbtTileEntity.getInteger("BannerRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("BannerRotation", mrot4[BannerRotation]);
return metadata;
case 2:
nbtTileEntity.setInteger("BannerRotation", mrot4[mrot4[BannerRotation]]);
return metadata;
case 3:
nbtTileEntity.setInteger("BannerRotation", mrot4[mrot4[mrot4[BannerRotation]]]);
return metadata;
default:
return metadata;
}
}
if (nbtTileEntity.hasKey("BorderRotation")) {
final int BorderRotation = nbtTileEntity.getInteger("BorderRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("BorderRotation", mrot4[BorderRotation]);
return metadata;
case 2:
nbtTileEntity.setInteger("BorderRotation", mrot4[mrot4[BorderRotation]]);
return metadata;
case 3:
nbtTileEntity.setInteger("BorderRotation", mrot4[mrot4[mrot4[BorderRotation]]]);
return metadata;
default:
return metadata;
}
}
if (nbtTileEntity.hasKey("SignRotation")) {
final int SignRotation = nbtTileEntity.getInteger("SignRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("SignRotation", mrot4[SignRotation]);
return metadata;
case 2:
nbtTileEntity.setInteger("SignRotation", mrot4[mrot4[SignRotation]]);
return metadata;
case 3:
nbtTileEntity.setInteger("SignRotation", mrot4[mrot4[mrot4[SignRotation]]]);
return metadata;
return mrotMailbox[mrotMailbox[mrotMailbox[metadata]]];
default:
return metadata;
}

View file

@ -0,0 +1,249 @@
package cr0s.warpdrive.compat;
import cr0s.warpdrive.api.IBlockTransformer;
import cr0s.warpdrive.api.ITransformation;
import cr0s.warpdrive.api.WarpDriveText;
import cr0s.warpdrive.config.WarpDriveConfig;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class CompatVariedCommodities implements IBlockTransformer {
// Varied commodities
private static Class<?> classBlockBasicContainer;
private static Class<?> classBlockBlood;
private static Class<?> classBlockCarpentryBench;
public static void register() {
try {
// varied commodities
classBlockBasicContainer = Class.forName("noppes.vc.blocks.BlockBasicContainer");
classBlockBlood = Class.forName("noppes.vc.blocks.BlockBlood");
classBlockCarpentryBench = Class.forName("noppes.vc.blocks.BlockCarpentryBench");
WarpDriveConfig.registerBlockTransformer("VariedCommodities", new CompatVariedCommodities());
} catch(final ClassNotFoundException exception) {
exception.printStackTrace();
}
}
@Override
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
return classBlockBasicContainer.isInstance(block);
}
@Override
public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, final WarpDriveText reason) {
return true;
}
@Override
public NBTBase saveExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do
return null;
}
@Override
public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do
}
/*
Transformation handling required:
noppes.vc.blocks.BlockBasicContainer
noppes.vc.blocks.BlockBanner / variedcommodities:banner
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockBigSign / variedcommodities:big_sign
int SignRotation 0 1 2 3
noppes.vc.blocks.BlockBlood / variedcommodities:blood_block
bool HideNorth
bool HideSouth
bool HideEast
bool HideWest
int Rotation 0 1 2 3
noppes.vc.blocks.BlockCarpentryBench / variedcommodities:carpentry_bench
meta 0 1 2 3 / 4 5 6 7
noppes.vc.blocks.BlockCouchWood / variedcommodities:couch_wood
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockCouchWool / variedcommodities:couch_wool
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockTallLamp / variedcommodities:tall_lamp
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockTombstone / variedcommodities:tombstone
int SignRotation 0 1 2 3
noppes.vc.blocks.BlockTrading / variedcommodities:trading_block
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockWallBanner / variedcommodities:wall_banner
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockBasicRotated
noppes.vc.blocks.BlockBarrel / variedcommodities:barrel
int BannerRotation 0 2 4 6 / 1 3 5 7
noppes.vc.blocks.BlockBasicLightable
BlockCampfire / variedcommodities:campfire
int BannerRotation 0 1 2 3 4 5 6 7
BlockCandle / variedcommodities:candle
int BannerRotation 0 1 2 3 4 5 6 7
BlockLamp / variedcommodities:lamp
int BannerRotation 0 1 2 3 4 5 6 7
noppes.vc.blocks.BlockBasicTrigger
BlockPedestal / variedcommodities:pedestal
int BannerRotation 0 1 2 3
BlockWeaponRack / variedcommodities:weapon_rack
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockBeam / variedcommodities:beam
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockBook / variedcommodities:book
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockChair / variedcommodities:chair
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockCrate / variedcommodities:crate
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockShelf / variedcommodities:shelf
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockSign / variedcommodities:sign
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockStool / variedcommodities:stool
int BannerRotation 0 1 2 3
noppes.vc.blocks.BlockTable / variedcommodities:table always 2 ?
int BannerRotation 0 1 2 3
No handling required:
noppes.vc.blocks.BlockCrystal
noppes.vc.blocks.BlockPlaceholder
*/
// ----------------------------------------- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] mrotCarpentryBench = { 1, 2, 3, 0, 5, 6, 7, 4, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] rot4 = { 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private static final int[] rot8 = { 2, 3, 4, 5, 6, 7, 0, 1, 8, 9, 10, 11, 12, 13, 14, 15 };
@Override
public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) {
final byte rotationSteps = transformation.getRotationSteps();
if (rotationSteps == 0) {
return metadata;
}
// BannerRotation NBT with no metadata change
if ( nbtTileEntity != null
&& nbtTileEntity.hasKey("BannerRotation") ) {
// get the rotation matrix
final String idTileEntity = nbtTileEntity.getString("id");
final int[] rot;
switch(idTileEntity) {
case "variedcommodities:barrel":
case "variedcommodities:campfire":
case "variedcommodities:candle":
case "variedcommodities:lamp":
rot = rot8;
break;
default:
rot = rot4;
break;
}
// apply
final int BannerRotation = nbtTileEntity.getInteger("BannerRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("BannerRotation", rot[BannerRotation]);
return metadata;
case 2:
nbtTileEntity.setInteger("BannerRotation", rot[rot[BannerRotation]]);
return metadata;
case 3:
nbtTileEntity.setInteger("BannerRotation", rot[rot[rot[BannerRotation]]]);
return metadata;
default:
return metadata;
}
}
// Carpentry bench is just metadata
if (classBlockCarpentryBench.isInstance(block)) {
switch (rotationSteps) {
case 1:
return mrotCarpentryBench[metadata];
case 2:
return mrotCarpentryBench[mrotCarpentryBench[metadata]];
case 3:
return mrotCarpentryBench[mrotCarpentryBench[mrotCarpentryBench[metadata]]];
default:
return metadata;
}
}
// Signs
if ( nbtTileEntity != null
&& nbtTileEntity.hasKey("SignRotation") ) {
final int SignRotation = nbtTileEntity.getInteger("SignRotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setInteger("SignRotation", rot4[SignRotation]);
return metadata;
case 2:
nbtTileEntity.setInteger("SignRotation", rot4[rot4[SignRotation]]);
return metadata;
case 3:
nbtTileEntity.setInteger("SignRotation", rot4[rot4[rot4[SignRotation]]]);
return metadata;
default:
return metadata;
}
}
// Blood use compass directions
if ( classBlockBlood.isInstance(block)
&& nbtTileEntity != null ) {
final boolean HideNorth = nbtTileEntity.getBoolean("HideNorth");
final boolean HideEast = nbtTileEntity.getBoolean("HideEast");
final boolean HideSouth = nbtTileEntity.getBoolean("HideSouth");
final boolean HideWest = nbtTileEntity.getBoolean("HideWest");
final int Rotation = nbtTileEntity.getInteger("Rotation");
switch (rotationSteps) {
case 1:
nbtTileEntity.setBoolean("HideNorth", HideWest );
nbtTileEntity.setBoolean("HideEast" , HideNorth);
nbtTileEntity.setBoolean("HideSouth", HideEast );
nbtTileEntity.setBoolean("HideWest" , HideSouth);
nbtTileEntity.setInteger("Rotation", rot4[Rotation]);
return metadata;
case 2:
nbtTileEntity.setBoolean("HideNorth", HideSouth);
nbtTileEntity.setBoolean("HideEast" , HideWest );
nbtTileEntity.setBoolean("HideSouth", HideNorth);
nbtTileEntity.setBoolean("HideWest" , HideEast );
nbtTileEntity.setInteger("Rotation", rot4[rot4[Rotation]]);
return metadata;
case 3:
nbtTileEntity.setBoolean("HideNorth", HideEast );
nbtTileEntity.setBoolean("HideEast" , HideSouth);
nbtTileEntity.setBoolean("HideSouth", HideWest );
nbtTileEntity.setBoolean("HideWest" , HideNorth);
nbtTileEntity.setInteger("Rotation", rot4[rot4[rot4[Rotation]]]);
return metadata;
default:
return metadata;
}
}
return metadata;
}
@Override
public void restoreExternals(final World world, final BlockPos blockPos,
final IBlockState blockState, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do
}
}

View file

@ -13,7 +13,7 @@ import cr0s.warpdrive.compat.CompatBotania;
import cr0s.warpdrive.compat.CompatBuildCraft;
import cr0s.warpdrive.compat.CompatCarpentersBlocks;
import cr0s.warpdrive.compat.CompatComputerCraft;
import cr0s.warpdrive.compat.CompatCustomNpcs;
import cr0s.warpdrive.compat.CompatCustomNPCs;
import cr0s.warpdrive.compat.CompatDecocraft;
import cr0s.warpdrive.compat.CompatDeepResonance;
import cr0s.warpdrive.compat.CompatDraconicEvolution;
@ -52,6 +52,7 @@ import cr0s.warpdrive.compat.CompatThaumcraft;
import cr0s.warpdrive.compat.CompatThermalDynamics;
import cr0s.warpdrive.compat.CompatThermalExpansion;
import cr0s.warpdrive.compat.CompatUndergroundBiomes;
import cr0s.warpdrive.compat.CompatVariedCommodities;
import cr0s.warpdrive.compat.CompatWarpDrive;
import cr0s.warpdrive.compat.CompatWoot;
import cr0s.warpdrive.compat.CompatYABBA;
@ -1442,9 +1443,9 @@ public class WarpDriveConfig {
CompatCarpentersBlocks.register();
}
final boolean isCustomNpcsLoaded = Loader.isModLoaded("customnpcs");
if (isCustomNpcsLoaded) {
CompatCustomNpcs.register();
final boolean isCustomNPCsLoaded = Loader.isModLoaded("customnpcs");
if (isCustomNPCsLoaded) {
CompatCustomNPCs.register();
}
final boolean isDecocraftLoaded = Loader.isModLoaded("props");
@ -1607,6 +1608,11 @@ public class WarpDriveConfig {
CompatUndergroundBiomes.register();
}
final boolean isVariedCommoditiesLoaded = Loader.isModLoaded("variedcommodities");
if (isVariedCommoditiesLoaded) {
CompatVariedCommodities.register();
}
final boolean isWootloaded = Loader.isModLoaded("woot");
if (isWootloaded) {
CompatWoot.register();