use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.
the class AnimationTESR method renderTileEntityFast.
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
return;
}
if (blockRenderer == null)
blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos pos = te.getPos();
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
IBlockState state = world.getBlockState(pos);
if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
state = state.withProperty(Properties.StaticProperty, false);
}
if (state instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) state;
if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
float time = Animation.getWorldTime(getWorld(), partialTick);
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null) {
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
}
}
}
}
use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.
the class UniversalBucket method onFillBucket.
// low priority so other mods can handle their stuff first
@SubscribeEvent(priority = EventPriority.LOW)
public void onFillBucket(FillBucketEvent event) {
if (event.getResult() != Event.Result.DEFAULT) {
// event was already handled
return;
}
// not for us to handle
ItemStack emptyBucket = event.getEmptyBucket();
if (emptyBucket.isEmpty() || !emptyBucket.isItemEqual(getEmpty()) || (isNbtSensitive() && ItemStack.areItemStackTagsEqual(emptyBucket, getEmpty()))) {
return;
}
// needs to target a block
RayTraceResult target = event.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
return;
}
World world = event.getWorld();
BlockPos pos = target.getBlockPos();
ItemStack singleBucket = emptyBucket.copy();
singleBucket.setCount(1);
FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, event.getEntityPlayer(), world, pos, target.sideHit);
if (filledResult.isSuccess()) {
event.setResult(Event.Result.ALLOW);
event.setFilledBucket(filledResult.getResult());
} else {
// cancel event, otherwise the vanilla minecraft ItemBucket would
// convert it into a water/lava bucket depending on the blocks material
event.setCanceled(true);
}
}
use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.
the class DispenseFluidContainer method fillContainer.
/**
* Picks up fluid in front of a Dispenser and fills a container with it.
*/
@Nonnull
private ItemStack fillContainer(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
World world = source.getWorld();
EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
ItemStack resultStack = actionResult.getResult();
if (!actionResult.isSuccess() || resultStack.isEmpty()) {
return super.dispenseStack(source, stack);
}
if (stack.getCount() == 1) {
return resultStack;
} else if (((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(resultStack) < 0) {
this.dispenseBehavior.dispense(source, resultStack);
}
ItemStack stackCopy = stack.copy();
stackCopy.shrink(1);
return stackCopy;
}
use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.
the class DispenseFluidContainer method dumpContainer.
/**
* Drains a filled container and places the fluid in front of the Dispenser.
*/
@Nonnull
private ItemStack dumpContainer(IBlockSource source, @Nonnull ItemStack stack) {
ItemStack singleStack = stack.copy();
singleStack.setCount(1);
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack);
if (fluidHandler == null) {
return super.dispenseStack(source, stack);
}
FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false);
EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
FluidActionResult result = fluidStack != null ? FluidUtil.tryPlaceFluid(null, source.getWorld(), blockpos, stack, fluidStack) : FluidActionResult.FAILURE;
if (result.isSuccess()) {
ItemStack drainedStack = result.getResult();
if (drainedStack.getCount() == 1) {
return drainedStack;
} else if (!drainedStack.isEmpty() && ((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(drainedStack) < 0) {
this.dispenseBehavior.dispense(source, drainedStack);
}
ItemStack stackCopy = drainedStack.copy();
stackCopy.shrink(1);
return stackCopy;
} else {
return this.dispenseBehavior.dispense(source, stack);
}
}
use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.
the class VanillaInventoryCodeHooks method dropperInsertHook.
/**
* Copied from BlockDropper#dispense and added capability support
*/
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, @Nonnull ItemStack stack) {
EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
BlockPos blockpos = pos.offset(enumfacing);
Pair<IItemHandler, Object> destinationResult = getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite());
if (destinationResult == null) {
return true;
} else {
IItemHandler itemHandler = destinationResult.getKey();
Object destination = destinationResult.getValue();
ItemStack dispensedStack = stack.copy().splitStack(1);
ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
if (remainder.isEmpty()) {
remainder = stack.copy();
remainder.shrink(1);
} else {
remainder = stack.copy();
}
dropper.setInventorySlotContents(slot, remainder);
return false;
}
}
Aggregations