Skip to content

Commit

Permalink
Fixed dedicated server crashes and ground anchor matching
Browse files Browse the repository at this point in the history
  • Loading branch information
impiaaa committed Jan 10, 2015
1 parent a56114c commit 309bd88
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/boatcake/MyWorldGen/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;

import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.item.Item;

public abstract class CommonProxy {
Expand All @@ -14,4 +15,7 @@ public abstract class CommonProxy {

public abstract void registerBlock(Block block, int metadata,
String blockName);

public abstract void registerVariants(Block block, PropertyEnum prop,
String postfix);
}
31 changes: 6 additions & 25 deletions src/main/java/net/boatcake/MyWorldGen/MyWorldGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import net.boatcake.MyWorldGen.blocks.BlockIgnore;
import net.boatcake.MyWorldGen.blocks.BlockPlacementIgnore;
import net.boatcake.MyWorldGen.blocks.TileEntityAnchorInventory;
import net.boatcake.MyWorldGen.client.NamespacedStateMap;
import net.boatcake.MyWorldGen.items.BlockAnchorItem;
import net.boatcake.MyWorldGen.items.ItemWandLoad;
import net.boatcake.MyWorldGen.items.ItemWandSave;
import net.boatcake.MyWorldGen.utils.FileUtils;
import net.boatcake.MyWorldGen.utils.NetUtils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -150,33 +147,16 @@ public Item getTabIconItem() {
BlockAnchorMaterialLogic.class);

if (materialAnchorBlock != null) {
String[] names = new String[BlockAnchorMaterial.AnchorType
.values().length];
for (int i = 0; i < names.length; i++) {
names[i] = MODID + ":"
+ BlockAnchorMaterial.AnchorType.get(i).name
+ "_anchor";
}
ModelBakery.addVariantName(
Item.getItemFromBlock(materialAnchorBlock), names);
Minecraft
.getMinecraft()
.getRenderItem()
.getItemModelMesher()
.getModelManager()
.getBlockModelShapes()
.func_178121_a(
materialAnchorBlock,
new NamespacedStateMap(
BlockAnchorMaterial.TYPE_PROP,
"_anchor"));
sidedProxy.registerVariants(materialAnchorBlock,
BlockAnchorMaterial.TYPE_PROP, "_anchor");
}

int defaultId;
if (materialAnchorBlock == null) {
defaultId = 1575;
} else {
defaultId = GameData.getBlockRegistry().getId(materialAnchorBlock);
defaultId = GameData.getBlockRegistry().getId(
materialAnchorBlock);
}
prop = cfg
.get("blocks", "materialAnchorBlock", defaultId,
Expand All @@ -200,7 +180,8 @@ public Item getTabIconItem() {
if (inventoryAnchorBlock == null) {
defaultId = 1577;
} else {
defaultId = GameData.getBlockRegistry().getId(inventoryAnchorBlock);
defaultId = GameData.getBlockRegistry().getId(
inventoryAnchorBlock);
}
prop = cfg
.get("blocks", "inventoryAnchorBlock", defaultId,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/boatcake/MyWorldGen/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ public void placeInWorld(World world, BlockPos at,
EnumFacing facing = (EnumFacing) state
.getValue(prop);
for (int i = 0; i < rotationCount; i++) {
facing = facing.rotateAround(rotationAxis);
facing = DirectionUtils.rotateAround(facing,
rotationAxis);
}
IBlockState rotatedState = state.withProperty(prop,
facing);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/boatcake/MyWorldGen/ServerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;

import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.relauncher.Side;
Expand All @@ -26,4 +27,8 @@ public void registerItem(Item item, int metadata, String itemName) {
@Override
public void registerBlock(Block block, int metadata, String blockName) {
}

@Override
public void registerVariants(Block block, PropertyEnum prop, String postfix) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static boolean matchesStatic(AnchorType myType,
IBlockState otherState, BiomeGenBase currentBiome) {
switch (myType) {
case GROUND:
return otherState.getBlock() == currentBiome.topBlock;
return otherState.equals(currentBiome.topBlock);
case AIR:
return otherState.getBlock() instanceof BlockAir
|| (otherState.getBlock().getMaterial().isReplaceable() && !otherState
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/boatcake/MyWorldGen/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import java.io.File;

import net.boatcake.MyWorldGen.CommonProxy;
import net.boatcake.MyWorldGen.MyWorldGen;
import net.boatcake.MyWorldGen.WorldGenerator;
import net.boatcake.MyWorldGen.blocks.BlockAnchorMaterial;
import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -37,4 +41,17 @@ public void registerItem(Item item, int metadata, String itemName) {
public void registerBlock(Block block, int metadata, String blockName) {
registerItem(Item.getItemFromBlock(block), metadata, blockName);
}

@Override
public void registerVariants(Block block, PropertyEnum prop, String postfix) {
String[] names = new String[BlockAnchorMaterial.AnchorType.values().length];
for (int i = 0; i < names.length; i++) {
names[i] = MyWorldGen.MODID + ":"
+ BlockAnchorMaterial.AnchorType.get(i).name + postfix;
}
ModelBakery.addVariantName(Item.getItemFromBlock(block), names);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.getModelManager().getBlockModelShapes()
.func_178121_a(block, new NamespacedStateMap(prop, postfix));
}
}
49 changes: 49 additions & 0 deletions src/main/java/net/boatcake/MyWorldGen/utils/DirectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,53 @@ public static EnumFacing getDirectionFromYaw(float yaw) {
return cardinalDirections[MathHelper
.floor_double(yaw * 4.0F / 360.0F + 0.5D) & 0x3];
}

// This method already exists in EnumFacing, but it's SideOnly(CLIENT) for
// some reason >:(
public static EnumFacing rotateAround(EnumFacing facing,
EnumFacing.Axis axis) {
switch (axis) {
case X:
switch (facing) {
case NORTH:
return EnumFacing.DOWN;
case EAST:
case WEST:
default:
return facing;
case SOUTH:
return EnumFacing.UP;
case UP:
return EnumFacing.NORTH;
case DOWN:
return EnumFacing.SOUTH;
}

case Y:
if (facing != EnumFacing.UP && facing != EnumFacing.DOWN) {
return facing.rotateY();
}
return facing;

case Z:
switch (facing) {
case EAST:
return EnumFacing.DOWN;
case NORTH:
case SOUTH:
default:
return facing;
case WEST:
return EnumFacing.UP;
case UP:
return EnumFacing.EAST;
case DOWN:
return EnumFacing.WEST;
}

default:
throw new IllegalStateException("Unable to get CW facing for axis "
+ axis);
}
}
}

0 comments on commit 309bd88

Please sign in to comment.