2017-10-04 17:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
2018-02-28 21:06:33 +01:00
|
|
|
* Copyright (C) 2016-2018 malte0811
|
2017-10-04 17:05:04 +02:00
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package malte0811.industrialWires.converter;
|
|
|
|
|
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
|
|
|
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
|
|
|
import malte0811.industrialWires.util.LocalSidedWorld;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraft.block.Block;
|
2018-02-17 20:37:53 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
|
|
|
import net.minecraft.client.renderer.block.model.BakedQuadRetextured;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2017-10-04 17:05:04 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2017-10-04 17:05:04 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2018-02-17 20:37:53 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
public class MechPartFlywheel extends MechMBPart {
|
2018-02-08 22:08:21 +01:00
|
|
|
private static final double RADIUS = 1.25;
|
2018-02-17 20:37:53 +01:00
|
|
|
private static final double THICKNESS = 1;
|
2018-02-08 22:08:21 +01:00
|
|
|
private static final double VOLUME = Math.PI*RADIUS*RADIUS*THICKNESS;
|
2017-10-04 17:05:04 +02:00
|
|
|
private Material material;
|
2018-06-04 18:10:52 +02:00
|
|
|
public MechPartFlywheel() {}
|
|
|
|
|
|
|
|
public MechPartFlywheel(Material m) {
|
|
|
|
material = m;
|
|
|
|
}
|
2017-10-04 17:05:04 +02:00
|
|
|
//A flywheel simply adds mass (lots of mass!), it doesn't actively change speeds/energy
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public void createMEnergy(MechEnergy e) {}
|
2017-10-04 17:05:04 +02:00
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public double requestMEnergy(MechEnergy e) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public void insertMEnergy(double added) {}
|
2017-10-04 17:05:04 +02:00
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public double getInertia() {
|
|
|
|
return .5*material.density*VOLUME*RADIUS*RADIUS;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-23 16:27:32 +01:00
|
|
|
public double getMaxSpeed() {
|
2018-02-08 22:08:21 +01:00
|
|
|
return Math.sqrt(material.tensileStrength /material.density)/RADIUS;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound out) {
|
|
|
|
out.setInteger("material", material.ordinal());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-28 21:03:26 +01:00
|
|
|
public void readFromNBT(NBTTagCompound in) {
|
|
|
|
material = Material.values()[in.getInteger("material")];
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getRotatingBaseModel() {
|
|
|
|
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/flywheel.obj");
|
|
|
|
}
|
|
|
|
|
2018-02-17 20:37:53 +01:00
|
|
|
@Override
|
2018-04-04 20:47:44 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2018-02-17 20:37:53 +01:00
|
|
|
public List<BakedQuad> getRotatingQuads() {
|
|
|
|
List<BakedQuad> orig = super.getRotatingQuads();
|
|
|
|
TextureAtlasSprite newTex = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(material.blockTexture.toString());
|
2018-02-28 21:03:26 +01:00
|
|
|
return orig.stream().map((quad)->{
|
|
|
|
if (quad.getSprite().getIconName().contains("steel")) {
|
|
|
|
return new BakedQuadRetextured(quad, newTex);
|
|
|
|
} else {
|
|
|
|
return quad;
|
|
|
|
}
|
|
|
|
}).collect(Collectors.toList());
|
2018-02-17 20:37:53 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
|
|
|
public boolean canForm(LocalSidedWorld w) {
|
|
|
|
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(-1, 1, 0);
|
|
|
|
try {
|
|
|
|
material = null;
|
|
|
|
for (Material m:Material.values()) {
|
|
|
|
if (m.matchesBlock(w, pos, "block")) {
|
|
|
|
material = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (material==null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int x = -1;x<=1;x++) {
|
|
|
|
for (int y = -1;y<=1;y++) {
|
|
|
|
pos.setPos(x, y, 0);
|
|
|
|
if ((x!=0||y!=0)&&!material.matchesBlock(w, pos, "block")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos.setPos(0, 0, 0);
|
2018-02-17 20:37:53 +01:00
|
|
|
return isValidDefaultCenter(w.getBlockState(pos));
|
2017-10-04 17:05:04 +02:00
|
|
|
} finally {
|
|
|
|
pos.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 20:37:53 +01:00
|
|
|
@Override
|
2018-05-14 18:51:42 +02:00
|
|
|
public IBlockState getOriginalBlock(BlockPos pos) {
|
|
|
|
if (pos.equals(ORIGIN)) {
|
|
|
|
return getDefaultShaft();
|
|
|
|
}
|
|
|
|
for (ItemStack block: OreDictionary.getOres("block"+material.oreName())) {
|
|
|
|
if (block.getItem() instanceof ItemBlock) {
|
|
|
|
ItemBlock ib = (ItemBlock) block.getItem();
|
|
|
|
return ib.getBlock().getStateFromMeta(block.getMetadata());
|
2018-02-17 20:37:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-14 18:51:42 +02:00
|
|
|
return Blocks.AIR.getDefaultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void breakOnFailure(MechEnergy energy) {
|
|
|
|
world.setBlockState(ORIGIN, getDefaultShaft());
|
|
|
|
IBlockState state = Blocks.AIR.getDefaultState();
|
2018-02-17 20:37:53 +01:00
|
|
|
for (int x = -1; x <= 1; x++) {
|
|
|
|
for (int y = -1; y <= 1; y++) {
|
|
|
|
if (x != 0 || y != 0) {
|
|
|
|
world.setBlockState(new BlockPos(x, y, 0), state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 18:51:42 +02:00
|
|
|
spawnBrokenParts(8, energy, material.blockTexture);
|
2018-02-17 20:37:53 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
2018-05-14 18:51:42 +02:00
|
|
|
public short getFormPattern(int offset) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return 0b111_111_111;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MechanicalMBBlockType getType() {
|
|
|
|
return MechanicalMBBlockType.FLYWHEEL;
|
|
|
|
}
|
2018-04-04 20:47:44 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
2018-05-14 18:51:42 +02:00
|
|
|
if (ORIGIN.equals(offsetPart)) {
|
2018-04-04 20:47:44 +02:00
|
|
|
return Block.FULL_BLOCK_AABB;
|
|
|
|
}
|
|
|
|
final double small = .375;
|
|
|
|
double xMin = offsetPart.getX()<=0?0:small;
|
|
|
|
double xMax = offsetPart.getX()>=0?1:1-small;
|
|
|
|
double yMin = offsetPart.getY()>=0?0:small;
|
|
|
|
double yMax = offsetPart.getY()<=0?1:1-small;
|
|
|
|
return new AxisAlignedBB(xMin, yMin, .0625, xMax, yMax, .9375);
|
|
|
|
}
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|