Skip to content

Commit

Permalink
another round of fixing
Browse files Browse the repository at this point in the history
also implemented request from Pokecube-Development#210, closes Pokecube-Development#210
  • Loading branch information
Thutmose committed Mar 7, 2020
1 parent ca375e2 commit c66d81a
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 152 deletions.
Binary file modified blender_files/gen_5/meloetta_aria.blend
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package pokecube.adventures.blocks.genetics.cloner;

import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluids;
Expand All @@ -21,145 +25,124 @@
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;

import org.jetbrains.annotations.NotNull;

import pokecube.core.blocks.InteractableHorizontalBlock;

public class ClonerBlock extends InteractableHorizontalBlock implements IWaterLoggable
{
private static final EnumProperty<ClonerBlockPart> HALF = EnumProperty.create("half", ClonerBlockPart.class);
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

//Precise selection box
private static final VoxelShape CLONER_BOTTOM = VoxelShapes.or(
makeCuboidShape(0, 0, 0, 16, 12, 16),
makeCuboidShape(0.74, 12, 0.74, 15.26, 13, 15.26),
makeCuboidShape(1.13, 13, 1.02, 15.03, 16, 14.93))
.simplify();

private static final VoxelShape CLONER_TOP = VoxelShapes.or(
makeCuboidShape(0, 12, 0, 16, 16, 16),
makeCuboidShape(0.74, 11, 0.74, 15.26, 12, 15.26),
makeCuboidShape(1.13, 0, 1.02, 15.03, 11, 14.93))
.simplify();

//Precise selection box
@NotNull
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
private static final EnumProperty<ClonerBlockPart> HALF = EnumProperty.create("half", ClonerBlockPart.class);
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

// Precise selection box
private static final VoxelShape CLONER_BOTTOM = VoxelShapes.or(Block.makeCuboidShape(0, 0, 0, 16, 12, 16), Block
.makeCuboidShape(0.74, 12, 0.74, 15.26, 13, 15.26), Block.makeCuboidShape(1.13, 13, 1.02, 15.03, 16, 14.93))
.simplify();

private static final VoxelShape CLONER_TOP = VoxelShapes.or(Block.makeCuboidShape(0, 12, 0, 16, 16, 16), Block
.makeCuboidShape(0.74, 11, 0.74, 15.26, 12, 15.26), Block.makeCuboidShape(1.13, 0, 1.02, 15.03, 11, 14.93))
.simplify();

// Precise selection box
@Override
public VoxelShape getShape(final BlockState state, final IBlockReader worldIn, final BlockPos pos,
final ISelectionContext context)
{
ClonerBlockPart half = state.get(HALF);
if (half == ClonerBlockPart.BOTTOM)
{
return CLONER_BOTTOM;
}
else {
return CLONER_TOP;
}
final ClonerBlockPart half = state.get(ClonerBlock.HALF);
if (half == ClonerBlockPart.BOTTOM) return ClonerBlock.CLONER_BOTTOM;
else return ClonerBlock.CLONER_TOP;
}

//Default States
public ClonerBlock(Properties properties)
// Default States
public ClonerBlock(final Properties properties)
{
super(properties);
this.setDefaultState(this.stateContainer.getBaseState()
.with(HALF, ClonerBlockPart.BOTTOM)
.with(HorizontalBlock.HORIZONTAL_FACING, Direction.NORTH)
.with(WATERLOGGED, false));
this.setDefaultState(this.stateContainer.getBaseState().with(ClonerBlock.HALF, ClonerBlockPart.BOTTOM).with(
HorizontalBlock.HORIZONTAL_FACING, Direction.NORTH).with(ClonerBlock.WATERLOGGED, false));
}

//Places Cloner with both top and bottom pieces
// Places Cloner with both top and bottom pieces
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack)
public void onBlockPlacedBy(final World world, final BlockPos pos, final BlockState state,
final LivingEntity placer, final ItemStack stack)
{
if (placer != null)
{
IFluidState fluidState = world.getFluidState(pos.up());
world.setBlockState(pos.up(),
state.with(HALF, ClonerBlockPart.TOP)
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER), 1);
final IFluidState fluidState = world.getFluidState(pos.up());
world.setBlockState(pos.up(), state.with(ClonerBlock.HALF, ClonerBlockPart.TOP).with(
ClonerBlock.WATERLOGGED, fluidState.getFluid() == Fluids.WATER), 1);
}
}

//Breaking Cloner breaks both parts and returns one item only
public void onBlockHarvested(World world, @NotNull BlockPos pos, BlockState state, @NotNull PlayerEntity player)
// Breaking Cloner breaks both parts and returns one item only
@Override
public void onBlockHarvested(final World world, final BlockPos pos, final BlockState state,
final PlayerEntity player)
{
Direction facing = state.get(HORIZONTAL_FACING);
BlockPos clonerPos = getClonerPos(pos, state.get(HALF), facing);
final Direction facing = state.get(HorizontalBlock.HORIZONTAL_FACING);
final BlockPos clonerPos = this.getClonerPos(pos, state.get(ClonerBlock.HALF), facing);
BlockState clonerBlockState = world.getBlockState(clonerPos);
if (clonerBlockState.getBlock() == this && !pos.equals(clonerPos))
{
removeHalf(world, clonerPos, clonerBlockState);
}
BlockPos clonerPartPos = getClonerTopPos(clonerPos, facing);
if (clonerBlockState.getBlock() == this && !pos.equals(clonerPos)) this.removeHalf(world, clonerPos,
clonerBlockState);
final BlockPos clonerPartPos = this.getClonerTopPos(clonerPos, facing);
clonerBlockState = world.getBlockState(clonerPartPos);
if (clonerBlockState.getBlock() == this && !pos.equals(clonerPartPos))
{
removeHalf(world, clonerPartPos, clonerBlockState);
}
if (clonerBlockState.getBlock() == this && !pos.equals(clonerPartPos)) this.removeHalf(world, clonerPartPos,
clonerBlockState);
super.onBlockHarvested(world, pos, state, player);
}

private BlockPos getClonerTopPos(BlockPos base, Direction facing)
private BlockPos getClonerTopPos(final BlockPos base, final Direction facing)
{
switch (facing) {
default:
return base.up();
switch (facing)
{
default:
return base.up();
}
}

private BlockPos getClonerPos(BlockPos pos, ClonerBlockPart part, Direction facing)
private BlockPos getClonerPos(final BlockPos pos, final ClonerBlockPart part, final Direction facing)
{
if (part == ClonerBlockPart.BOTTOM) return pos;
switch (facing) {
default:
return pos.down();
switch (facing)
{
default:
return pos.down();
}
}

//Breaking the Cloner leaves water if underwater
private void removeHalf(World world, BlockPos pos, BlockState state)
// Breaking the Cloner leaves water if underwater
private void removeHalf(final World world, final BlockPos pos, final BlockState state)
{
IFluidState fluidState = world.getFluidState(pos);
if (fluidState.getFluid() == Fluids.WATER)
{
world.setBlockState(pos, fluidState.getBlockState(), 35);
}
else {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 35);
}
final IFluidState fluidState = world.getFluidState(pos);
if (fluidState.getFluid() == Fluids.WATER) world.setBlockState(pos, fluidState.getBlockState(), 35);
else world.setBlockState(pos, Blocks.AIR.getDefaultState(), 35);
}

//Prevents the Cloner from replacing blocks above it and checks for water
// Prevents the Cloner from replacing blocks above it and checks for water
@Override
public BlockState getStateForPlacement(BlockItemUseContext context)
public BlockState getStateForPlacement(final BlockItemUseContext context)
{
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
BlockPos pos = context.getPos();

BlockPos clonerPos = getClonerTopPos(pos, context.getPlacementHorizontalFacing().getOpposite());
if (pos.getY() < 255 &&
clonerPos.getY() < 255 && context.getWorld().getBlockState(pos.up()).isReplaceable(context))
{
return this.getDefaultState()
.with(HorizontalBlock.HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite())
.with(HALF, ClonerBlockPart.BOTTOM)
.with(WATERLOGGED, ifluidstate.isTagged(FluidTags.WATER) && ifluidstate.getLevel() == 8);
}
final IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
final BlockPos pos = context.getPos();

final BlockPos clonerPos = this.getClonerTopPos(pos, context.getPlacementHorizontalFacing().getOpposite());
if (pos.getY() < 255 && clonerPos.getY() < 255 && context.getWorld().getBlockState(pos.up()).isReplaceable(
context)) return this.getDefaultState().with(HorizontalBlock.HORIZONTAL_FACING, context
.getPlacementHorizontalFacing().getOpposite()).with(ClonerBlock.HALF, ClonerBlockPart.BOTTOM)
.with(ClonerBlock.WATERLOGGED, ifluidstate.isTagged(FluidTags.WATER) && ifluidstate
.getLevel() == 8);
return null;
}

@NotNull
@SuppressWarnings("deprecation")
@Override
public IFluidState getFluidState(BlockState state)
public IFluidState getFluidState(final BlockState state)
{
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
return state.get(ClonerBlock.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
@Override
protected void fillStateContainer(final StateContainer.Builder<Block, BlockState> builder)
{
builder.add(HALF, HorizontalBlock.HORIZONTAL_FACING, WATERLOGGED);
builder.add(ClonerBlock.HALF, HorizontalBlock.HORIZONTAL_FACING, ClonerBlock.WATERLOGGED);
}

@Override
Expand All @@ -175,8 +158,8 @@ public boolean hasTileEntity(final BlockState state)
}

@Override
public boolean canRenderInLayer(BlockState state, BlockRenderLayer layer)
public boolean canRenderInLayer(final BlockState state, final BlockRenderLayer layer)
{
return (layer == BlockRenderLayer.CUTOUT) || (layer == BlockRenderLayer.TRANSLUCENT);
return layer == BlockRenderLayer.CUTOUT || layer == BlockRenderLayer.TRANSLUCENT;
}
}
21 changes: 20 additions & 1 deletion src/main/java/pokecube/core/items/vitamins/ItemVitamin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@

import com.google.common.collect.Lists;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import pokecube.core.interfaces.PokecubeMod;

public class ItemVitamin extends Item
Expand All @@ -13,11 +22,21 @@ public class ItemVitamin extends Item

public final String type;

public ItemVitamin(Properties properties, String type)
public ItemVitamin(final Properties properties, final String type)
{
super(properties);
this.type = type;
this.setRegistryName(PokecubeMod.ID, "vitamin_" + type);
}

@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(final ItemStack stack, final World worldIn, final List<ITextComponent> tooltip,
final ITooltipFlag flagIn)
{
String message;
if (Screen.hasShiftDown()) message = I18n.format("pokecube.tooltip." + this.type);
else message = I18n.format("pokecube.tooltip.advanced");
tooltip.add(new TranslationTextComponent(message));
}
}
64 changes: 32 additions & 32 deletions src/main/java/pokecube/mobs/MiscItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,40 @@ public ActionResult<ItemStack> onMoveTick(final IPokemob pokemob, final ItemStac

static ItemStack CHARCOALSTACK;

public static ActionResult<ItemStack> feedToPokemob(final ItemStack stack, final Entity entity)
private static ActionResult<ItemStack> applyEVs(final byte[] evs, final ItemStack stack, final IPokemob pokemob)
{
final IPokemob pokemob = CapabilityPokemob.getPokemobFor(entity);
if (pokemob != null)
boolean fed = false;
for (int i = 0; i < evs.length; i++)
{
if (PokecubeItems.is(new ResourceLocation("pokecube:hpup"), stack))
final byte toAdd = evs[i];
final byte ev = pokemob.getEVs()[i];
if (toAdd > 0 && ev < Byte.MAX_VALUE)
{
pokemob.addEVs(new byte[] { 10, 0, 0, 0, 0, 0 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
if (PokecubeItems.is(new ResourceLocation("pokecube:protein"), stack))
{
pokemob.addEVs(new byte[] { 0, 10, 0, 0, 0, 0 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
if (PokecubeItems.is(new ResourceLocation("pokecube:iron"), stack))
{
pokemob.addEVs(new byte[] { 0, 0, 10, 0, 0, 0 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
if (PokecubeItems.is(new ResourceLocation("pokecube:calcium"), stack))
{
pokemob.addEVs(new byte[] { 0, 0, 0, 10, 0, 0 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
if (PokecubeItems.is(new ResourceLocation("pokecube:zinc"), stack))
{
pokemob.addEVs(new byte[] { 0, 0, 0, 0, 10, 0 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
if (PokecubeItems.is(new ResourceLocation("pokecube:carbos"), stack))
{
pokemob.addEVs(new byte[] { 0, 0, 0, 0, 0, 10 });
return new ActionResult<>(ActionResultType.SUCCESS, stack);
fed = true;
break;
}
}
return new ActionResult<>(fed ? ActionResultType.SUCCESS : ActionResultType.FAIL, stack);
}

private static ActionResult<ItemStack> feedVitamin(final ItemStack stack, final Entity entity)
{
final IPokemob pokemob = CapabilityPokemob.getPokemobFor(entity);
if (pokemob != null)
{
if (PokecubeItems.is(new ResourceLocation("pokecube:hpup"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 10, 0, 0, 0, 0, 0 }, stack, pokemob);
if (PokecubeItems.is(new ResourceLocation("pokecube:protein"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 0, 10, 0, 0, 0, 0 }, stack, pokemob);
if (PokecubeItems.is(new ResourceLocation("pokecube:iron"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 0, 0, 10, 0, 0, 0 }, stack, pokemob);
if (PokecubeItems.is(new ResourceLocation("pokecube:calcium"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 0, 0, 0, 10, 0, 0 }, stack, pokemob);
if (PokecubeItems.is(new ResourceLocation("pokecube:zinc"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 0, 10, 0, 0, 10, 0 }, stack, pokemob);
if (PokecubeItems.is(new ResourceLocation("pokecube:carbos"), stack)) return MiscItemHelper.applyEVs(
new byte[] { 0, 0, 0, 0, 0, 10 }, stack, pokemob);
}
return new ActionResult<>(ActionResultType.FAIL, stack);
}

Expand All @@ -105,7 +103,9 @@ public static void init()
@Override
public ActionResult<ItemStack> onUse(final IPokemob pokemob, final ItemStack stack, final LivingEntity user)
{
return MiscItemHelper.feedToPokemob(stack, pokemob.getEntity());
final ActionResult<ItemStack> result = MiscItemHelper.feedVitamin(stack, pokemob.getEntity());
// TODO decide on whether to send a message if it fails?
return result;
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/pokecube/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@
"pokecube.tooltip.ability": "A: %s",
"pokecube.tooltip.advanced": "<Shift for more info>",

"pokecube.tooltip.hpup": "Increases HP of a Pokémob",
"pokecube.tooltip.protein": "Increases ATT of a Pokémob",
"pokecube.tooltip.iron": "Increases DEF of a Pokémob",
"pokecube.tooltip.calcium": "Increases ATTSP of a Pokémob",
"pokecube.tooltip.zinc": "Increases DEFSP of a Pokémob",
"pokecube.tooltip.carbos": "Increases VIT of a Pokémob",

"_comment": "Mob Internal Names",

"entity.pokecube.egg": "Pokémob Egg",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<ModelAnimator version="0.1">
<model name="">
<phase name="global" scale="0.35"/>
<phase name="global" offset="0,0,0" rotation="1,0,0,0" scale="0.35"/>
<metadata head="head" headAxis="2" headAxis2="0" headCap="-10,10" headCap1="-10,10" headDir="-1" headDir2="-1"/>
<customTex default="shellder">
<part name="Head" tex="shellderhead"/>
<animation diffs="0,0.5" part="Head" trigger="random:0.005:25"/>
<animation diffs="0,0.5" part="Head" trigger="random:0.005:1"/>
</customTex>
<phase type="idle">
<part name="l">
Expand Down
Loading

0 comments on commit c66d81a

Please sign in to comment.