Skip to content

Commit

Permalink
FIx fence gate render
Browse files Browse the repository at this point in the history
Fix door drop item
  • Loading branch information
Alexander Kornilov committed Jun 29, 2018
1 parent 81c3f98 commit 56a89b9
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 185 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ New versions will be created in branched named like {mc_version}-{mod_version}

#### IntelliJ IDEA

1. Execute the following gradle command to setup your workspace and create the necessary idea project files:
1. Execute the following gradle command to setup your workspace:

```
./gradlew setupDecompWorkspace idea genIntellijRuns
```
```
./gradlew setupDecompWorkspace
```

2. Open the `*.ipr` project file using IntelliJ IDEA
2. Open IntelliJ IDEA and import Gradle project

3. Select `Minecraft Client` from _Run configurations_ and press the green play button.
3. Close IntelliJ IDEA

4. Execute the following gradle command to create the necessary idea project files:

```
./gradlew genIntellijRuns
```

5. Select `Minecraft Client` from _Run configurations_ and press the green play button.
Minecraft should now launch with Binnie and all of its dependencies loaded :)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
apply plugin: "net.minecraftforge.gradle.forge"

version = "2.5"
version = "2.6"
group = "ru.kordum.totemDefender"
archivesBaseName = "TotemDefender-1.12.2"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/kordum/totemDefender/TotemDefender.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class TotemDefender {
public static final String MODID = "totemdefender";
public static final String NAME = "Totem Defender";
public static final String VERSION = "2.5";
public static final String VERSION = "2.6";

@SidedProxy(
clientSide = "ru.kordum.totemDefender.proxy.ClientProxy",
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/ru/kordum/totemDefender/block/BlockDoor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
package ru.kordum.totemDefender.block;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ru.kordum.totemDefender.handler.ItemRegistry;

import javax.annotation.Nonnull;
import java.util.Random;

public class BlockDoor extends net.minecraft.block.BlockDoor {
public BlockDoor() {
super(Material.WOOD);
setHardness(4);
}

@Nonnull
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return state.getValue(HALF) == EnumDoorHalf.UPPER ? Items.AIR : getItem();
}

@Nonnull
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
return new ItemStack(getItem());
}

private Item getItem() {
return ItemRegistry.DOOR;
}
}
92 changes: 60 additions & 32 deletions src/main/java/ru/kordum/totemDefender/block/BlockFenceGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class BlockFenceGate extends BlockHorizontal {
public static final PropertyBool OPEN = PropertyBool.create("open");
public static final PropertyBool POWERED = PropertyBool.create("powered");
public static final PropertyBool IN_WALL = PropertyBool.create("in_wall");
protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
protected static final AxisAlignedBB AABB_COLLIDE_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS_INWALL = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 0.8125D, 0.625D);
protected static final AxisAlignedBB AABB_COLLIDE_XAXIS_INWALL = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 0.8125D, 1.0D);
protected static final AxisAlignedBB AABB_CLOSED_SELECTED_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
protected static final AxisAlignedBB AABB_CLOSED_SELECTED_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 1.0D);
protected static final AxisAlignedBB AABB_HITBOX_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
protected static final AxisAlignedBB AABB_HITBOX_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
protected static final AxisAlignedBB AABB_HITBOX_ZAXIS_INWALL = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 0.8125D, 0.625D);
protected static final AxisAlignedBB AABB_HITBOX_XAXIS_INWALL = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 0.8125D, 1.0D);
protected static final AxisAlignedBB AABB_COLLISION_BOX_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
protected static final AxisAlignedBB AABB_COLLISION_BOX_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 1.0D);

public BlockFenceGate() {
super(Material.WOOD, Material.WOOD.getMaterialMapColor());
Expand All @@ -44,60 +45,84 @@ public BlockFenceGate() {
setHardness(4);
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
state = getActualState(state, source, pos);
state = this.getActualState(state, source, pos);
if (state.getValue(IN_WALL).booleanValue()) {
return state.getValue(FACING).getAxis() == EnumFacing.Axis.X ? AABB_COLLIDE_XAXIS_INWALL : AABB_COLLIDE_ZAXIS_INWALL;
return state.getValue(FACING).getAxis() == EnumFacing.Axis.X
? AABB_HITBOX_XAXIS_INWALL
: AABB_HITBOX_ZAXIS_INWALL;
}
return state.getValue(FACING).getAxis() == EnumFacing.Axis.X
? AABB_COLLIDE_XAXIS
: AABB_COLLIDE_ZAXIS;
? AABB_HITBOX_XAXIS
: AABB_HITBOX_ZAXIS;
}

public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
EnumFacing.Axis enumfacing$axis = state.getValue(FACING).getAxis();

if (enumfacing$axis == EnumFacing.Axis.Z && (canFenceGateConnectTo(worldIn, pos, EnumFacing.WEST) || canFenceGateConnectTo(worldIn, pos, EnumFacing.EAST)) || enumfacing$axis == EnumFacing.Axis.X && (canFenceGateConnectTo(worldIn, pos, EnumFacing.NORTH) || canFenceGateConnectTo(worldIn, pos, EnumFacing.SOUTH))) {
state = state.withProperty(IN_WALL, Boolean.valueOf(true));
@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
EnumFacing.Axis axis = state.getValue(FACING).getAxis();
if (axis == EnumFacing.Axis.Z && (world.getBlockState(pos.west()).getBlock() instanceof BlockWall || world.getBlockState(pos.east()).getBlock() instanceof BlockWall) || axis == EnumFacing.Axis.X && (world.getBlockState(pos.north()).getBlock() instanceof BlockWall || world.getBlockState(pos.south()).getBlock() instanceof BlockWall)) {
state = state.withProperty(IN_WALL, Boolean.TRUE);
}

return state;
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
}

public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return worldIn.getBlockState(pos.down()).getMaterial().isSolid() ? super.canPlaceBlockAt(worldIn, pos) : false;
@Override
public boolean canPlaceBlockAt(World world, BlockPos pos) {
return world.getBlockState(pos.down()).getMaterial().isSolid()
? super.canPlaceBlockAt(world, pos)
: false;
}

@SuppressWarnings("deprecation")
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess world, BlockPos pos) {
if (blockState.getValue(OPEN).booleanValue()) {
return NULL_AABB;
}
return blockState.getValue(FACING).getAxis() == EnumFacing.Axis.Z
? AABB_CLOSED_SELECTED_ZAXIS
: AABB_CLOSED_SELECTED_XAXIS;
? AABB_COLLISION_BOX_ZAXIS
: AABB_COLLISION_BOX_XAXIS;
}

@SuppressWarnings("deprecation")
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}

@SuppressWarnings("deprecation")
@Override
public boolean isFullCube(IBlockState state) {
return false;
}

@Override
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
return worldIn.getBlockState(pos).getValue(OPEN).booleanValue();
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
boolean flag = world.isBlockPowered(pos);
return getDefaultState()
Expand All @@ -107,6 +132,7 @@ public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing fa
.withProperty(IN_WALL, Boolean.FALSE);
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (state.getValue(OPEN).booleanValue()) {
state = state.withProperty(OPEN, Boolean.FALSE);
Expand All @@ -125,6 +151,8 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
return true;
}

@SuppressWarnings("deprecation")
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
if (!world.isRemote) {
boolean flag = world.isBlockPowered(pos);
Expand All @@ -139,10 +167,15 @@ public void neighborChanged(IBlockState state, World world, BlockPos pos, Block
}

@SideOnly(Side.CLIENT)
@SuppressWarnings("deprecation")
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return true;
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(FACING, EnumFacing.getHorizontal(meta))
Expand All @@ -151,18 +184,18 @@ public IBlockState getStateFromMeta(int meta) {
}

public int getMetaFromState(IBlockState state) {
int i = 0;
i = i | state.getValue(FACING).getHorizontalIndex();

int meta = state.getValue(FACING).getHorizontalIndex();
if (state.getValue(POWERED).booleanValue()) {
i |= 8;
meta |= 8;
}
if (state.getValue(OPEN).booleanValue()) {
i |= 4;
meta |= 4;
}
return i;
return meta;
}

@Nonnull
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, FACING, OPEN, POWERED, IN_WALL);
}
Expand All @@ -173,9 +206,4 @@ public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing fac
return connector instanceof BlockFence
|| connector instanceof BlockWall;
}

private boolean canFenceGateConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
Block block = world.getBlockState(pos.offset(facing)).getBlock();
return block.canBeConnectedTo(world, pos.offset(facing), facing.getOpposite());
}
}
20 changes: 11 additions & 9 deletions src/main/java/ru/kordum/totemDefender/block/BlockLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ public BlockLeaves(int saplingChance) {
this.saplingChance = saplingChance;
}

@Nonnull
@Override
public List<ItemStack> onSheared(@Nonnull ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
if (!(item.getItem() instanceof ItemShears)) {
return null;
}

List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(this));
if (item.getItem() instanceof ItemShears) {
list.add(new ItemStack(this));
}
return list;
}

@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
Expand All @@ -42,21 +43,22 @@ public IBlockState getStateFromMeta(int meta) {

@Override
public int getMetaFromState(IBlockState state) {
int i = 0;
int meta = 0;
if (!state.getValue(DECAYABLE)) {
i |= 4;
meta |= 4;
}
if (state.getValue(CHECK_DECAY)) {
i |= 8;
meta |= 8;
}
return i;
return meta;
}

@Override
protected int getSaplingDropChance(IBlockState state) {
return saplingChance;
}

@Nonnull
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, CHECK_DECAY, DECAYABLE);
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/ru/kordum/totemDefender/block/BlockLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;

import javax.annotation.Nonnull;

public class BlockLog extends net.minecraft.block.BlockLog implements IBlockWithSubTypes {
public static final PropertyEnum<EnumType> VARIANT = PropertyEnum.create("variant", EnumType.class);

Expand All @@ -18,11 +18,13 @@ public BlockLog() {
setDefaultState(state);
}

@Nonnull
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, LOG_AXIS, VARIANT);
}

@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
IBlockState state = getDefaultState().withProperty(VARIANT, EnumType.byMeta(meta));
Expand All @@ -42,25 +44,21 @@ public IBlockState getStateFromMeta(int meta) {
@Override
public int getMetaFromState(IBlockState state) {
EnumType type = state.getValue(VARIANT);
int i = type.ordinal();
int meta = type.getMeta();
switch (SwitchEnumAxis.AXIS_LOOKUP[state.getValue(LOG_AXIS).ordinal()]) {
case 1:
i |= 4;
meta |= 4;
break;

case 2:
i |= 8;
meta |= 8;
break;

case 3:
i |= 12;
meta |= 12;
break;
}
return i;
}

@Override
protected ItemStack getSilkTouchDrop(IBlockState state) {
return new ItemStack(Item.getItemFromBlock(this), 1, state.getValue(VARIANT).ordinal());
return meta;
}

@Override
Expand Down Expand Up @@ -114,6 +112,11 @@ public static EnumType byMeta(int meta) {
return null;
}

public int getMeta() {
return ordinal();
}

@Nonnull
@Override
public String getName() {
return name;
Expand Down
Loading

0 comments on commit 56a89b9

Please sign in to comment.