use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo in project pnc-repressurized by TeamPneumatic.
the class ItemCamoApplicator method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
if (player.isSneaking()) {
// copy blockstate of clicked block
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockPneumaticCraftCamo) {
NetworkHandler.sendToAllAround(new PacketPlaySound(SoundEvents.BLOCK_COMPARATOR_CLICK, SoundCategory.PLAYERS, pos, 1.0F, 2.0F, false), world);
player.sendStatusMessage(new TextComponentTranslation("message.camo.invalidBlock", getCamoStateDisplayName(state)), true);
} else {
setCamoState(stack, state);
}
} else {
// either apply saved camo, or remove current camo from block
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof ICamouflageableTE)) {
return EnumActionResult.PASS;
}
IBlockState camoState = getCamoState(stack);
float pressure = getPressure(stack);
if (pressure < 0.1 && !player.capabilities.isCreativeMode) {
// not enough pressure
return EnumActionResult.FAIL;
}
// make sure player has enough of the camo item
if (camoState != null && !player.capabilities.isCreativeMode) {
ItemStack camoStack = ICamouflageableTE.getStackForState(camoState);
if (!PneumaticCraftUtils.consumeInventoryItem(player.inventory, camoStack)) {
String name = camoStack.getDisplayName();
player.sendStatusMessage(new TextComponentTranslation("message.camo.notEnoughBlocks", name), true);
NetworkHandler.sendToAllAround(new PacketPlaySound(SoundEvents.BLOCK_COMPARATOR_CLICK, SoundCategory.PLAYERS, pos, 1.0F, 2.0F, false), world);
return EnumActionResult.FAIL;
}
}
// return any existing camouflage on the block/TE
IBlockState existingCamo = ((ICamouflageableTE) te).getCamouflage();
if (existingCamo != null && !player.capabilities.isCreativeMode) {
ItemStack camoStack = ICamouflageableTE.getStackForState(existingCamo);
EntityItem entity = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, camoStack);
world.spawnEntity(entity);
entity.onCollideWithPlayer(player);
}
// and apply the new camouflage
addAir(stack, -PneumaticValues.USAGE_CAMO_APPLICATOR);
((ICamouflageableTE) te).setCamouflage(camoState);
NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.SHORT_HISS, SoundCategory.PLAYERS, pos, 1.0F, 1.0F, false), world);
return EnumActionResult.SUCCESS;
}
} else {
return EnumActionResult.SUCCESS;
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo in project pnc-repressurized by TeamPneumatic.
the class CamoModel method handleBlockState.
private IBakedModel handleBlockState(IBlockState state) {
if (state instanceof IExtendedBlockState) {
IExtendedBlockState ext = (IExtendedBlockState) state;
IBlockState camoState = ext.getValue(BlockPneumaticCraftCamo.CAMO_STATE);
if (camoState != null && !(camoState.getBlock() instanceof BlockPneumaticCraftCamo)) {
BlockModelShapes blockModelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
return blockModelShapes.getModelForState(camoState);
}
}
return originalModel;
}
use of me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo in project pnc-repressurized by TeamPneumatic.
the class ClientEventHandler method onModelBaking.
@SubscribeEvent
public void onModelBaking(ModelBakeEvent event) {
// set up camo models for camouflagable blocks
for (Block block : Blockss.blocks) {
if (block instanceof BlockPneumaticCraftCamo) {
Map<IBlockState, ModelResourceLocation> map = event.getModelManager().getBlockModelShapes().getBlockStateMapper().getVariants(block);
for (Map.Entry<IBlockState, ModelResourceLocation> entry : map.entrySet()) {
Object object = event.getModelRegistry().getObject(entry.getValue());
if (object != null) {
IBakedModel existing = (IBakedModel) object;
CamoModel customModel = new CamoModel(existing);
event.getModelRegistry().putObject(entry.getValue(), customModel);
}
}
}
}
}
Aggregations