use of net.minecraft.entity.item.ItemFrameEntity in project Structurize by ldtteam.
the class ItemStackUtils method getListOfStackForEntity.
/**
* Get the list of required resources for entities.
*
* @param entity the entity object.
* @param pos the placer pos..
* @return a list of stacks.
*/
public static List<ItemStack> getListOfStackForEntity(final Entity entity, final BlockPos pos) {
if (entity != null) {
final List<ItemStack> request = new ArrayList<>();
if (entity instanceof ItemFrameEntity) {
final ItemStack stack = ((ItemFrameEntity) entity).getItem();
if (!ItemStackUtils.isEmpty(stack)) {
stack.setCount(1);
request.add(stack);
}
request.add(new ItemStack(Items.ITEM_FRAME, 1));
} else if (entity instanceof ArmorStandEntity) {
request.add(entity.getPickedResult(new RayTraceResult(Vector3d.atLowerCornerOf(pos)) {
@NotNull
@Override
public Type getType() {
return Type.ENTITY;
}
}));
entity.getArmorSlots().forEach(request::add);
entity.getHandSlots().forEach(request::add);
}
return request.stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of net.minecraft.entity.item.ItemFrameEntity in project ChocolateQuestRepoured by TeamChocoQuest.
the class PreparableMapInfo method prepare.
@Override
protected GeneratablePosInfo prepare(World world, DungeonPlacement placement, BlockPos pos) {
Direction transformedFacing = placement.getRotation().rotate(placement.getMirror().mirror(this.facing));
ItemFrameEntity entity = new ItemFrameEntity(world, pos.toImmutable(), transformedFacing);
switch(this.orientation) {
case EAST:
entity.setItemRotation(entity.getRotation() + 3);
break;
case SOUTH:
entity.setItemRotation(entity.getRotation() + 2);
break;
case WEST:
entity.setItemRotation(entity.getRotation() + 1);
break;
default:
break;
}
int x1 = this.offsetX * (128 << this.scale);
int z1 = this.offsetZ * (128 << this.scale);
int x2 = this.originX;
int z2 = this.originZ;
switch(placement.getMirror()) {
case LEFT_RIGHT:
if (!this.lockOrientation) {
if (this.orientation.getAxis() == Axis.Z) {
entity.setItemRotation(entity.getRotation() + 2);
}
z1 = -z1;
} else {
if (this.orientation.getAxis() == Axis.X) {
z1 = -z1;
}
if (this.orientation.getAxis() == Axis.Z) {
x1 = -x1;
}
}
z2 = -z2;
break;
case FRONT_BACK:
if (!this.lockOrientation) {
if (this.orientation.getAxis() == Axis.X) {
entity.setItemRotation(entity.getRotation() + 2);
}
x1 = -x1;
} else {
if (this.orientation.getAxis() == Axis.X) {
z1 = -z1;
}
if (this.orientation.getAxis() == Axis.Z) {
x1 = -x1;
}
}
x2 = -x2;
break;
default:
break;
}
int x3 = x1;
int z3 = z1;
int x4 = x2;
int z4 = z2;
switch(placement.getRotation()) {
case COUNTERCLOCKWISE_90:
if (!this.lockOrientation) {
entity.setItemRotation(entity.getRotation() + 1);
x1 = z3;
z1 = -x3;
}
x2 = z4;
z2 = -x4;
break;
case CLOCKWISE_90:
if (!this.lockOrientation) {
entity.setItemRotation(entity.getRotation() + 3);
x1 = -z3;
z1 = x3;
}
x2 = -z4;
z2 = x4;
break;
case CLOCKWISE_180:
if (!this.lockOrientation) {
entity.setItemRotation(entity.getRotation() + 2);
x1 = -x3;
z1 = -z3;
}
x2 = -x4;
z2 = -z4;
break;
default:
break;
}
return new GeneratableMapInfo(pos, entity, pos.getX() + x2, pos.getZ() + z2, pos.getX() + x1 + x2, pos.getZ() + z1 + z2, this.scale, this.fillMap, this.fillRadius);
}
use of net.minecraft.entity.item.ItemFrameEntity in project minecolonies by Minecolonies.
the class ItemStackUtils method getListOfStackForEntity.
/**
* Adds entities to the builder building if he needs it.
*
* @param entity the entity object.
* @param placer the entity placer.
* @return a list of stacks.
*/
public static List<ItemStorage> getListOfStackForEntity(final Entity entity, final Entity placer) {
if (entity != null) {
final List<ItemStorage> request = new ArrayList<>();
if (entity instanceof ItemFrameEntity) {
final ItemStack stack = ((ItemFrameEntity) entity).getItem();
if (!ItemStackUtils.isEmpty(stack)) {
ItemStackUtils.setSize(stack, 1);
request.add(new ItemStorage(stack));
}
request.add(new ItemStorage(new ItemStack(Items.ITEM_FRAME, 1)));
} else if (entity instanceof ArmorStandEntity) {
request.add(new ItemStorage(entity.getPickedResult(new EntityRayTraceResult(placer))));
entity.getArmorSlots().forEach(item -> request.add(new ItemStorage(item)));
entity.getHandSlots().forEach(item -> request.add(new ItemStorage(item)));
}
return request.stream().filter(stack -> !stack.getItemStack().isEmpty()).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of net.minecraft.entity.item.ItemFrameEntity in project Arclight by IzzelAliz.
the class TrackedEntityMixin method tick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
List<Entity> list = this.trackedEntity.getPassengers();
if (!list.equals(this.passengers)) {
this.passengers = list;
this.sendPacket(new SSetPassengersPacket(this.trackedEntity));
}
if (this.trackedEntity instanceof ItemFrameEntity) {
ItemFrameEntity entityitemframe = (ItemFrameEntity) this.trackedEntity;
ItemStack itemstack = entityitemframe.getDisplayedItem();
if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof FilledMapItem) {
MapData worldmap = FilledMapItem.getMapData(itemstack, this.world);
for (ServerPlayerEntity entityplayer : this.trackedPlayers) {
worldmap.updateVisiblePlayers(entityplayer, itemstack);
IPacket<?> packet = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, entityplayer);
if (packet != null) {
entityplayer.connection.sendPacket(packet);
}
}
}
this.sendMetadata();
}
if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) {
if (this.trackedEntity.isPassenger()) {
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
boolean flag = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag) {
this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround));
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
}
this.updateEncodedPosition();
this.sendMetadata();
this.riding = true;
} else {
++this.ticksSinceAbsoluteTeleport;
int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
Vec3d vec3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
boolean flag2 = vec3d.lengthSquared() >= 7.62939453125E-6;
IPacket<?> packet2 = null;
boolean flag3 = flag2 || this.updateCounter % 60 == 0;
boolean flag4 = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
if (flag3) {
this.updateEncodedPosition();
}
if (flag4) {
this.encodedRotationYaw = i;
this.encodedRotationPitch = j;
}
if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) {
long k = SEntityPacket.func_218743_a(vec3d.x);
long l = SEntityPacket.func_218743_a(vec3d.y);
long i2 = SEntityPacket.func_218743_a(vec3d.z);
boolean flag5 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i2 < -32768L || i2 > 32767L;
if (!flag5 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.onGround) {
if ((!flag3 || !flag4) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
if (flag3) {
packet2 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, this.trackedEntity.onGround);
} else if (flag4) {
packet2 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround);
}
} else {
packet2 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, (byte) i, (byte) j, this.trackedEntity.onGround);
}
} else {
this.onGround = this.trackedEntity.onGround;
this.ticksSinceAbsoluteTeleport = 0;
packet2 = new SEntityTeleportPacket(this.trackedEntity);
}
}
if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || (this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying())) && this.updateCounter > 0) {
Vec3d vec3d2 = this.trackedEntity.getMotion();
double d0 = vec3d2.squareDistanceTo(this.velocity);
if (d0 > 1.0E-7 || (d0 > 0.0 && vec3d2.lengthSquared() == 0.0)) {
this.velocity = vec3d2;
this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
}
}
if (packet2 != null) {
this.packetConsumer.accept(packet2);
}
this.sendMetadata();
this.riding = false;
}
int i = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
if (Math.abs(i - this.encodedRotationYawHead) >= 1) {
this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) i));
this.encodedRotationYawHead = i;
}
this.trackedEntity.isAirBorne = false;
}
++this.updateCounter;
if (this.trackedEntity.velocityChanged) {
boolean cancelled = false;
if (this.trackedEntity instanceof ServerPlayerEntity) {
Player player = ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity();
Vector velocity = player.getVelocity();
PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cancelled = true;
} else if (!velocity.equals(event.getVelocity())) {
player.setVelocity(event.getVelocity());
}
}
if (!cancelled) {
this.sendPacket(new SEntityVelocityPacket(this.trackedEntity));
}
this.trackedEntity.velocityChanged = false;
}
}
use of net.minecraft.entity.item.ItemFrameEntity in project Structurize by ldtteam.
the class BlueprintRenderer method draw.
/**
* Draws structure into world.
*/
public void draw(final BlockPos pos, final MatrixStack matrixStack, final float partialTicks) {
Minecraft.getInstance().getProfiler().push("struct_render_init");
if (Settings.instance.shouldRefresh()) {
init();
}
Minecraft.getInstance().getProfiler().popPush("struct_render_blocks");
final Minecraft mc = Minecraft.getInstance();
final Vector3d viewPosition = mc.gameRenderer.getMainCamera().getPosition();
final BlockPos primaryBlockOffset = blockAccess.getBlueprint().getPrimaryBlockOffset();
final int x = pos.getX() - primaryBlockOffset.getX();
final int y = pos.getY() - primaryBlockOffset.getY();
final int z = pos.getZ() - primaryBlockOffset.getZ();
// missing clipping helper? frustum?
// missing chunk system and render distance!
matrixStack.pushPose();
matrixStack.translate(x - viewPosition.x(), y - viewPosition.y(), z - viewPosition.z());
final Matrix4f rawPosMatrix = matrixStack.last().pose();
// Render blocks
Minecraft.getInstance().getProfiler().popPush("struct_render_blocks_finish");
renderBlockLayer(RenderType.solid(), rawPosMatrix);
// FORGE: fix flickering leaves when mods mess up the blurMipmap settings
mc.getModelManager().getAtlas(AtlasTexture.LOCATION_BLOCKS).setBlurMipmap(false, mc.options.mipmapLevels > 0);
renderBlockLayer(RenderType.cutoutMipped(), rawPosMatrix);
mc.getModelManager().getAtlas(AtlasTexture.LOCATION_BLOCKS).restoreLastBlurMipmap();
renderBlockLayer(RenderType.cutout(), rawPosMatrix);
OptifineCompat.getInstance().endTerrainBeginEntities();
Minecraft.getInstance().getProfiler().popPush("struct_render_entities");
final IRenderTypeBuffer.Impl renderBufferSource = ClientEventSubscriber.renderBuffers.bufferSource();
// Entities
// if clipping etc., see WorldRenderer for what's missing
entities.forEach(entity -> {
if (entity instanceof ItemFrameEntity && ((ItemFrameEntity) entity).getItem().getItem() instanceof CompassItem) {
final ItemFrameEntity copy = EntityType.ITEM_FRAME.create(blockAccess);
copy.restoreFrom(entity);
copy.setItem(ItemStack.EMPTY);
entity = copy;
}
OptifineCompat.getInstance().preRenderEntity(entity);
Minecraft.getInstance().getEntityRenderDispatcher().render(entity, entity.getX(), entity.getY(), entity.getZ(), MathHelper.lerp(partialTicks, entity.yRotO, entity.yRot), 0, matrixStack, renderBufferSource, 200);
});
Minecraft.getInstance().getProfiler().popPush("struct_render_entities_finish");
renderBufferSource.endBatch(RenderType.entitySolid(AtlasTexture.LOCATION_BLOCKS));
renderBufferSource.endBatch(RenderType.entityCutout(AtlasTexture.LOCATION_BLOCKS));
renderBufferSource.endBatch(RenderType.entityCutoutNoCull(AtlasTexture.LOCATION_BLOCKS));
renderBufferSource.endBatch(RenderType.entitySmoothCutout(AtlasTexture.LOCATION_BLOCKS));
OptifineCompat.getInstance().endEntitiesBeginBlockEntities();
// Block entities
Minecraft.getInstance().getProfiler().popPush("struct_render_blockentities");
final ActiveRenderInfo oldActiveRenderInfo = TileEntityRendererDispatcher.instance.camera;
final World oldWorld = TileEntityRendererDispatcher.instance.level;
TileEntityRendererDispatcher.instance.camera = new ActiveRenderInfo();
TileEntityRendererDispatcher.instance.camera.setPosition(viewPosition.subtract(x, y, z));
TileEntityRendererDispatcher.instance.level = blockAccess;
tileEntities.forEach(tileEntity -> {
final BlockPos tePos = tileEntity.getBlockPos();
matrixStack.pushPose();
matrixStack.translate(tePos.getX(), tePos.getY(), tePos.getZ());
OptifineCompat.getInstance().preRenderBlockEntity(tileEntity);
TileEntityRendererDispatcher.instance.render(tileEntity, partialTicks, matrixStack, renderBufferSource);
matrixStack.popPose();
});
TileEntityRendererDispatcher.instance.camera = oldActiveRenderInfo;
TileEntityRendererDispatcher.instance.level = oldWorld;
Minecraft.getInstance().getProfiler().popPush("struct_render_blockentities_finish");
renderBufferSource.endBatch(RenderType.solid());
renderBufferSource.endBatch(Atlases.solidBlockSheet());
renderBufferSource.endBatch(Atlases.cutoutBlockSheet());
renderBufferSource.endBatch(Atlases.bedSheet());
renderBufferSource.endBatch(Atlases.shulkerBoxSheet());
renderBufferSource.endBatch(Atlases.signSheet());
renderBufferSource.endBatch(Atlases.chestSheet());
if (OptifineCompat.getInstance().isOptifineEnabled()) {
renderBufferSource.endBatch(Atlases.bannerSheet());
}
// not used now
ClientEventSubscriber.renderBuffers.outlineBufferSource().endOutlineBatch();
OptifineCompat.getInstance().endBlockEntitiesBeginDebug();
renderBufferSource.endBatch(Atlases.translucentCullBlockSheet());
renderBufferSource.endBatch(Atlases.bannerSheet());
renderBufferSource.endBatch(Atlases.shieldSheet());
renderBufferSource.endBatch(RenderType.armorGlint());
renderBufferSource.endBatch(RenderType.armorEntityGlint());
renderBufferSource.endBatch(RenderType.glint());
renderBufferSource.endBatch(RenderType.glintDirect());
renderBufferSource.endBatch(RenderType.glintTranslucent());
renderBufferSource.endBatch(RenderType.entityGlint());
renderBufferSource.endBatch(RenderType.entityGlintDirect());
renderBufferSource.endBatch(RenderType.waterMask());
// not used now
ClientEventSubscriber.renderBuffers.crumblingBufferSource().endBatch();
renderBufferSource.endBatch(RenderType.lines());
renderBufferSource.endBatch();
Minecraft.getInstance().getProfiler().popPush("struct_render_blocks_finish2");
OptifineCompat.getInstance().endDebugPreWaterBeginWater();
renderBlockLayer(RenderType.translucent(), rawPosMatrix);
OptifineCompat.getInstance().endWater();
renderBlockLayer(RenderType.tripwire(), rawPosMatrix);
matrixStack.popPose();
Minecraft.getInstance().getProfiler().pop();
}
Aggregations