use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class IngredientMaterial method createMatchingStacks.
@Override
protected ItemStack[][] createMatchingStacks() {
if (chain != null) {
List<ItemStack> stacks = new ArrayList<>();
for (ItemStack stack : dependency.getMatchingStacks()) {
ItemMaterial materialOut = getChainedMaterial(ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(stack));
if (materialOut != null) {
stacks.add(materialOut.getStack());
}
}
ItemStack[][] stackArrays = new ItemStack[stacks.size()][1];
for (int i = 0; i < stacks.size(); i++) {
stackArrays[i][0] = stacks.get(i);
}
return stackArrays;
} else {
Collection<ItemMaterial> mats = ItemMaterialRegistry.INSTANCE.getMaterialsByTypes(types);
ItemStack[][] stacks = new ItemStack[mats.size()][1];
int idx = 0;
for (ItemMaterial material : mats) {
stacks[idx++][0] = material.getStack();
}
return stacks;
}
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class RenderTileEntityStacks method getQuads.
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side != null || !(state instanceof IExtendedBlockState)) {
return Collections.emptyList();
}
TileEntityStacks stacks = ((IExtendedBlockState) state).getValue(BlockStacks.PROPERTY_TILE);
if (stacks == null || stacks.stacks.isEmpty()) {
return Collections.emptyList();
}
List<BakedQuad> list = new ArrayList<>();
int i = 0;
for (ItemMaterial material : stacks.stacks) {
Vec3d[] vecs = INGOT_POSITIONS[i];
ItemMaterial blockMaterial = material.getRelated("block");
TextureAtlasSprite sprite;
int c;
if (blockMaterial == null) {
ItemStack ingotStack = material.getStack();
sprite = RenderUtils.getItemSprite(new ItemStack(Blocks.IRON_BLOCK));
c = ColorLookupHandler.INSTANCE.getColor(ingotStack, RenderUtils.AveragingMode.FULL) | 0xFF000000;
} else {
sprite = RenderUtils.getItemSprite(blockMaterial.getStack());
c = Minecraft.getMinecraft().getItemColors().colorMultiplier(blockMaterial.getStack(), 0);
}
float[] color = new float[] { MathHelper.clamp(((c >> 16) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c >> 8) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c) & 0xFF) / 255.0f, 0, 1), 1.0f };
int j = 0;
int yOff = (i >> 3) & 1;
for (int[] vecOrder : QUAD_ORDERS[yOff]) {
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.ITEM);
EnumFacing face = QUAD_FACES[yOff][j];
builder.setTexture(sprite);
builder.setApplyDiffuseLighting(isAmbientOcclusion());
builder.setContractUVs(false);
builder.setQuadOrientation(face);
int uv_offset = j < 4 ? 1 : 0;
if (yOff == 1)
uv_offset = 1 - uv_offset;
for (int k = 0; k < vecOrder.length; k++) {
Vec3d vec = vecs[vecOrder[k]];
int[] uv = QUAD_UVS[(k + uv_offset) & 3];
for (int e = 0; e < builder.getVertexFormat().getElementCount(); e++) {
VertexFormatElement el = builder.getVertexFormat().getElement(e);
switch(el.getUsage()) {
case POSITION:
builder.put(e, (float) vec.x / 16f, (float) vec.y / 16f, (float) vec.z / 16f, 1);
break;
case COLOR:
builder.put(e, color);
break;
case NORMAL:
builder.put(e, face.getFrontOffsetX(), face.getFrontOffsetY(), face.getFrontOffsetZ(), 0);
break;
case UV:
float u = sprite.getInterpolatedU(uv[0]);
float v = sprite.getInterpolatedV(uv[1]);
builder.put(e, u, v, 0, 1);
break;
default:
builder.put(e);
}
}
}
list.add(builder.build());
j++;
}
i++;
}
return list;
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class TileEntityStacks method writeNBTData.
@Override
public NBTTagCompound writeNBTData(NBTTagCompound compound, boolean isClient) {
compound = super.writeNBTData(compound, isClient);
NBTTagList list = new NBTTagList();
for (ItemMaterial stack : stacks) {
NBTTagCompound cpd = new NBTTagCompound();
stack.writeToNBT(cpd, "material");
list.appendTag(cpd);
}
compound.setTag("stacks", list);
return compound;
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class TileEntityStacks method offerStack.
public boolean offerStack(ItemStack stack) {
if (!canAcceptStackType(stack) || stacks.size() >= 64) {
return false;
}
ItemMaterial material = ItemMaterialRegistry.INSTANCE.getMaterialIfPresent(stack);
stacks.add(material);
markBlockForUpdate();
return true;
}
use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.
the class CharsetTransportBoats method onJoinWorld.
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity().getClass() == EntityBoat.class) {
ItemStack boatStack = ItemBoatCharset.STACK.get();
ItemMaterial plankMaterial = (boatStack != null) ? ItemBoatCharset.getMaterial(boatStack) : ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(new ItemStack(Blocks.PLANKS, 1, ((EntityBoat) event.getEntity()).getBoatType().getMetadata()));
event.setCanceled(true);
EntityBoatCharset entityBoatCharset = new EntityBoatCharset(event.getWorld(), event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, plankMaterial);
entityBoatCharset.rotationYaw = event.getEntity().rotationYaw;
event.getWorld().spawnEntity(entityBoatCharset);
}
}
Aggregations